iOS 中,所有显示在界面上的对象都是从 UIResponder 直接或间接继承的,只有继承了它才可以处理事件。而在ios中的事件可以分为三大类:
1.触摸事件
2.加速计事件(摇一摇)
3.远程控制事件
只要手指触摸屏幕,滑动,从屏幕离开,系统都会产生UIEvent对象类型的事件---当然包括UITouch事件
/**
* 开始触摸(也就是手指触摸屏幕(view)那一刻)
*/
-(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;
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 = , // for UIEventTypeMotion, available in iPhone OS 3.0
UIEventSubtypeMotionShake = , // for UIEventTypeRemoteControl, available in iOS 4.0
UIEventSubtypeRemoteControlPlay = ,
UIEventSubtypeRemoteControlPause = ,
UIEventSubtypeRemoteControlStop = ,
UIEventSubtypeRemoteControlTogglePlayPause = ,
UIEventSubtypeRemoteControlNextTrack = ,
UIEventSubtypeRemoteControlPreviousTrack = ,
UIEventSubtypeRemoteControlBeginSeekingBackward = ,
UIEventSubtypeRemoteControlEndSeekingBackward = ,
UIEventSubtypeRemoteControlBeginSeekingForward = ,
UIEventSubtypeRemoteControlEndSeekingForward = ,
};