iOS事件處理

iOS中常用的事件

觸摸事件

加速計(jì)事件

遠(yuǎn)程控制事件

什么是響應(yīng)者對(duì)象

繼承了UIResponds的對(duì)象為響應(yīng)者對(duì)象

例如:UIApplication、UIViewController、UIView都繼承自UIResponder

所以它們都是響應(yīng)者對(duì)象,都能夠接收并處理事件

為什么說(shuō)繼承了UIResponder就能夠處理事件

因?yàn)樵赨IResponder內(nèi)部提供了以下方法來(lái)處理事件

例如:觸摸事件會(huì)調(diào)用以下方法:

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event;

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event;

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

加速計(jì)事件會(huì)調(diào)用:

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent*)event;

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event;

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent*)event;

遠(yuǎn)程控制事件會(huì)調(diào)用:

- (void)remoteControlReceivedWithEvent:(UIEvent*)event;

如何監(jiān)聽UIView的觸摸事件

想要監(jiān)聽UIViiew的觸摸事件,首先第一步要自定義UIView,

因?yàn)橹挥袑?shí)現(xiàn)了UIResponder的事件方法才能夠監(jiān)聽事件.

UIView的觸摸事件主要有:

手指開始觸摸view,系統(tǒng)會(huì)自動(dòng)調(diào)用:

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event

手指在view上移動(dòng)時(shí),系統(tǒng)會(huì)自動(dòng)調(diào)用:

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event

(在移動(dòng)過(guò)程中,會(huì)持續(xù)調(diào)用該方法,所以說(shuō)該方法會(huì)在移動(dòng)時(shí)一直調(diào)用)

手指離開view(停止觸摸),系統(tǒng)會(huì)自動(dòng)調(diào)用view的下面方法

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容