iOS 手势滑动事件绑定

UIGestureRecognizer 手势响应基类
- UITapGestureRecognizer //点击手势识别器,可以是点击一次,或多次都能识别
- UIPinchGestureRecognizer //捏合手势识别器,用于视图的放大缩小
- UIRotationGestureRecognizer //旋转手势识别器
- UISwipeGestureRecognizer //滑动手势识别器,向上、下、左、右滑动
- UIPanGestureRecognizer //拖动手势识别器
- UILongPressGestureRecognizer //长按手势识别器,常见的有长按跳出一个界面用以编辑


这里演示的是

UISwipeGestureRecognizer  // 上下左右的滑动

ps: 参数详解:self设置代理类,@selector设置事件响应,

然后要设置响应的是哪个view的手势

这里设置的是

self.gameView

/*
 * 绑定手势事件,上下左右
 **/
- (void)bindAction {
    UISwipeGestureRecognizer *recognizer;
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [self.gameView addGestureRecognizer:recognizer];
    
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
    [self.gameView addGestureRecognizer:recognizer];
   
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeTop)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
    [self.gameView addGestureRecognizer:recognizer];
    
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeBottom)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
    [self.gameView addGestureRecognizer:recognizer];
}




郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。