swipe.direction的值都是3.
下面是我以前的代码:
UISwipeGestureRecognizer *swiperight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swichController:)];
//默认是UISwipeGestureRecognizerDirectionRight
swiperight.direction=UISwipeGestureRecognizerDirectionRight|
UISwipeGestureRecognizerDirectionLeft
;[self.collection addGestureRecognizer:swiperight];
他是错误的。
正确的用法是,要创建俩个轻拍手势,分别设定他的方向才可以。
//添加轻扫手势
UISwipeGestureRecognizer *swipe=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swichController:)];
//默认是UISwipeGestureRecognizerDirectionRight
swipe.direction=UISwipeGestureRecognizerDirectionLeft;
[self.collection addGestureRecognizer:swipe];
UISwipeGestureRecognizer *swiperight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swichController:)];
//默认是UISwipeGestureRecognizerDirectionRight
swiperight.direction=UISwipeGestureRecognizerDirectionRight;
[self.collection addGestureRecognizer:swiperight];
本文解决了使用UISwipeGestureRecognizer时,无论滑动方向如何,direction值总是为3的问题。通过创建两个不同的手势对象,分别设置左右滑动方向,实现对不同滑动方向的识别。
1554

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



