手势

一、手势种类

  • UITapGestureRecognizer  点击
  • UIPinchGestureRecognizer 二指往内或往外拨动
  • UIRotationGestureRecognizer 旋转
  • UISwipeGestureRecognizer 滑动,快速移动
  • UIPanGestureRecognizer 拖移,慢速移动
  • UILongPressGestureRecognizer 长按

二、事件

   1、单击
   UITapGestureRecognizersingleRecognizer;
    singleRecognizer [[UITapGestureRecognizer allocinitWithTarget:selfaction:@selector(handleSingleTapFrom)];
    singleTapRecognizer.numberOfTapsRequired 1// 单击
    [self.view addGestureRecognizer:singleRecognizer];
  2、双击
    // 双击的 Recognizer
    UITapGestureRecognizerdouble;
    doubleRecognizer [[UITapGestureRecognizer allocinitWithTarget:selfaction:@selector(handleDoubleTapFrom)];
    doubleTapRecognizer.numberOfTapsRequired 2// 双击
    [self.view addGestureRecognizer:doubleRecognizer];
 

    // 关键在这一行,如果双击确定偵測失败才會触发单击

    [singleRecognizer requireGestureRecognizerToFail:doubleRecognizer];
 
3、二指往内或往外拨动
UIPinchGestureRecognizer *twoFingerPinch =[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)];
[self.view addGestureRecognizer:twoFingerPinch]; - (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer { NSLog(@"Pinch scale: %f", recognizer.scale);
}
 4、旋转
   UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
    [rotationRecognizer setDelegate:self];
    [self.view addGestureRecognizer:rotationRecognizer];
 
posted @ 2015-12-10 11:44  莫莫smile1  阅读(121)  评论(0编辑  收藏  举报