iOS 手势滑动事件绑定
jopen
9年前
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]; }