UITouch UIGestureRecognizer

简介: 1:本次 touch 坐标 CGPoint point = [[touches anyObject] locationInView:self]; 2:上次 touch 坐标 CGPoint prevPoint = [[t...

1:本次 touch 坐标

CGPoint point = [[touches anyObject] locationInView:self];     

2:上次 touch 坐标

CGPoint prevPoint = [[touches anyObject] previousLocationInView:self];


3:利用 UIPinchGestureRecognizer 实现 View 通过 Transform 缩小放大.

第一步:注册手势捏合识别器

UIPinchGestureRecognizer *pinch = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(doPinch:)] autorelease];
[self addGestureRecognizer:pinch];


第二步:实现doPinch 方法

#pragma mark - UIPinchGestureRecognizer
- (void)doPinch:(UIPinchGestureRecognizer *)pinch
{
    CGAffineTransform newTransform = CGAffineTransformScale(self.transform, pinch.scale, pinch.scale);                 
    [self setTransform:newTransform];
    [pinch setScale:1];
}


4: UIGestureRecognizer 手势优先级调整(摘自:IOS开发之手势——UIGestureRecognizer 共存)

// 关键在这一行,如果双击确定偵測失败才會触发单击
[singleRecognizer requireGestureRecognizerToFail:doubleRecognizer];

5:  UIGestureRecognizer 在成功触发事件以后,会有一个 状态来标识手势的实际触发情况,比如什么时候开始的,什么时候结束的 等

if (longGesture.state == UIGestureRecognizerStateBegan)

6:iOS 提供 6种系统级的手势供开发人员使用

1:UITapGestureRecognizer  Tap(点一下)

2:UIPinchGestureRecognizer Pinch(二指往內或往外拨动)

3:UIRotationGestureRecognizer Rotation(旋转)

4:UISwipeGestureRecognizer Swipe(滑动,快速移动)

5:UIPanGestureRecognizer Pan (拖移,慢速移动)

6:UILongPressGestureRecognizer LongPress(长按)

1:长按3秒后触发事件

longPressGR.minimumPressDuration = 3;
触发后:会调度两次所设定的方法,传入两个状态:

Begin  :成功按住那么久时触发

End :松手时触发


7:IOS6之前让UITapGestureRecognizer 和 UIButton 事件共存(iOS6以后默认支持)

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    // 过滤掉UIButton,也可以是其他类型
    if ([touch.view isKindOfClass:[UIButton class]])
    {
        return NO;
    }
    return YES;
}
注:如果在iOS6 想让TapGesture的action先执行,需要把cancelsTouchesInView设置成NO.


8:通过平移和速率来实现手势移动的视图交互

CGPoint velocity = [panGestureRecognizer velocityInView:controlPanelWindow];//速率
CGPoint translation = [panGestureRecognizer translationInView:controlPanelWindow];//平移




目录
相关文章
|
iOS开发
UISearchBar去除背景
UISearchBar去除背景
151 0
UISearchBar去除背景
|
开发者 iOS开发
UIDatePicker的详细讲解
UIDatePicker的详细讲解
433 0
 UIDatePicker的详细讲解
UINavigationBar-使用总结
UINavigationBar-使用总结
120 0