//*************************************** 方法 ****************************************** //
■ UIResponder内部提供了以下方法来处理事件
➢ 触摸事件
- (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;// 触摸事件被强迫取消 打电话进来了 ,就不能玩游戏了
➢ 加速计事件
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event; // 微信摇一摇
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event;
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event;
➢ 远程控制事件
- (void)remoteControlReceivedWithEvent:(UIEvent *)event; // 当系统的控制器点下一首的时候就会调用这个方法 酷狗
//*************************************** 步骤 ****************************************** //
■ UIView是UIResponder的子类,可以覆盖下列4个方法处理不同的触摸事件
➢ 一根或者多根手指开始触摸view,系统会自动调用view的下面方法
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
➢
➢ 一根或者多根手指在view上移动,系统会自动调用view的下面方法(随着手指的移动,会持续调用该方法)
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
➢
➢ 一根或者多根手指离开view,系统会自动调用view的下面方法
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
➢
➢ 触摸结束前,某个系统事件(例如电话呼入)会打断触摸过程,系统会自动调用view的下面方法
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
IOS学习之——UIResponder
最新推荐文章于 2024-05-05 23:44:56 发布