標籤:
iOS 中,所有顯示在介面上的對象都是從 UIResponder 直接或間接繼承的,只有繼承了它才可以處理事件。而在ios中的事件可以分為三大類:
1.觸摸事件
2.加速計事件(搖一搖)
3.遠端控制事件
只要手指觸控螢幕幕,滑動,從螢幕離開,系統都會產生UIEvent物件類型的事件---當然包括UITouch事件
1 /**2 * 開始觸摸(也就是手指觸控螢幕幕(view)那一刻)3 */4 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
1 /**2 * 觸摸進行中。。。。3 */4 -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
/** * 觸摸結束 */-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
1 /**2 * 觸摸中斷3 */4 -(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
iOS 3.0 + 開始支援motion事件,特別是搖動裝置,例如:中的搖一搖功能。
// 運動開始時執行
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0);
// 運動結束時執行
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0);
// 運動被取消時執行
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event NS_AVAILABLE_IOS(3_0);
iOS 4.0 + 開始支援遠程事件
- (void)remoteControlReceivedWithEvent:(UIEvent *)event NS_AVAILABLE_IOS(4_0);
// 下面是UIEventType三種事件類型的枚舉定義
typedef NS_ENUM(NSInteger, UIEventType) { UIEventTypeTouches, UIEventTypeMotion, UIEventTypeRemoteControl,};typedef NS_ENUM(NSInteger, UIEventSubtype) { // available in iPhone OS 3.0 UIEventSubtypeNone = 0, // for UIEventTypeMotion, available in iPhone OS 3.0 UIEventSubtypeMotionShake = 1, // for UIEventTypeRemoteControl, available in iOS 4.0 UIEventSubtypeRemoteControlPlay = 100, UIEventSubtypeRemoteControlPause = 101, UIEventSubtypeRemoteControlStop = 102, UIEventSubtypeRemoteControlTogglePlayPause = 103, UIEventSubtypeRemoteControlNextTrack = 104, UIEventSubtypeRemoteControlPreviousTrack = 105, UIEventSubtypeRemoteControlBeginSeekingBackward = 106, UIEventSubtypeRemoteControlEndSeekingBackward = 107, UIEventSubtypeRemoteControlBeginSeekingForward = 108, UIEventSubtypeRemoteControlEndSeekingForward = 109,};
IOS中的三大事件