iOS开发之手势gesture详解(二)

iOS开发之手势gesture详解(二)

  与其他用户界面控件交互

UIControl子类会覆盖parentView的gesture.例如当用户点击UIButton时,UIButton会接受触摸事件,它的parentView不会接收到.这仅适用于手势识别重叠的默认动作的控制,其中包括:

 

  • 一根手指单击动作:UIButton, UISwitch, UIStepper, UISegmentedControl, and UIPageControl. 
  • 一根手指擦碰动作:UISlider
  • 一根手指拖动动作:UISwitch

  包含多点触摸的事件

在iOS中,touch是指一根手指在屏幕上滑动、移动.而手势是指有一根或多根手指,它的类是UITouch对象.多点触摸事件是UIEventTypeTouches

 

 

 

当发生触摸时,会触发下列方法:

  • touchesBegan:withEvent :触摸屏幕时发生
  • touchesMoved:withEvent :手指在屏幕上移动时发生
  • touchesEnded:withEvent :触摸结束时发生,即手指离开屏幕时
  • touchesCancelled:withEvent :触摸被系统取消时发生,如有电话时,该触摸会被取消

 

 

改变默认的事件传递顺序

你可以通过改变UIGestureRecognizer子类的属性来改变默认的事件传递

  • @property(nonatomicBOOL delaysTouchesBegan;         // default is NO.  causes all touch events to be delivered to the target view only after this gesture has failed recognition. set to YES to prevent views from processing any touches that may be recognized as part of this gesture
  • @property(nonatomicBOOL delaysTouchesEnded;         // default is YES. causes touchesEnded events to be delivered to the target view only after this gesture has failed recognition. this ensures that a touch that is part of the gesture can be cancelled if the gesture is recognized

如果一个gesture recognizer检测到了一个不属于它的touch,它将手势直接发送给它的view,此时会调用ignoreTouch:forEvent: 方法直接传递给view.

创建自定义gesture recognizer步骤

  • 创建UIGestureRecognizer的子类
  • #import <UIKit/UIGestureRecognizerSubclass.h>
  • 在子类冲重载下列方法

 

1.- (void)reset;
2.- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
3.- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
4.- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
5.- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值