首先在view上添加手势 UIPanGestureRecognizer
1 UIPanGestureRecognizer *panGes = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(goAnimation:)]; 2 3 [self.view addGestureRecognizer:panGes];
在滑动方法当中根据 translationInView 这个方法返回的点的正负来判断向左还是向右 大于0说明向左,小于0说明向右
UIPanGestureRecognizer *pan = (UIPanGestureRecognizer *)sender; CGPoint point = [pan translationInView:self.view]; if (point.x>0) { //向左滑动 }else{ //向右滑动 }
本文介绍如何在iOS应用中使用UIPanGestureRecognizer实现左右滑动手势的识别,并通过translationInView方法判断手势方向。

1245

被折叠的 条评论
为什么被折叠?



