IOS学习之——UIResponder

本文详细介绍了iOS中UIResponder类处理触摸、加速计及远程控制事件的方法。具体包括开始触摸、触摸移动、触摸结束及触摸取消等触摸事件,以及开始、结束和取消的加速计事件,还有远程控制事件的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里写图片描述


//***************************************        方法       ****************************************** //


    ■   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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值