平移手势和滑动手势
Posted
技术标签:
【中文标题】平移手势和滑动手势【英文标题】:pan gesture and swipe gesture 【发布时间】:2014-03-04 05:18:31 【问题描述】:在我的项目中,我需要一个左右移动的滑动手势动作,我需要一个上下方向的平移手势动作。当我同时使用两个手势时,只有平移手势在调用。有人对此有解决方案吗?
UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(goToPreviosSong)];
rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:rightSwipe];
UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(goToNextSong)];
rightSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:leftSwipe];
对于 pan 我正在使用此代码
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
[self.view addGestureRecognizer:edgePanGesture];
【问题讨论】:
【参考方案1】:[panGesture requireGestureRecognizerToFail:rightSwipe];
[panGesture requireGestureRecognizerToFail:leftSwipe];
【讨论】:
【参考方案2】:如果其他手势识别器没有执行,请使用requireGestureRecognizerToFail:
来识别手势。
[rightSwipe requireGestureRecognizerToFail: panGesture];
[leftSwipe requireGestureRecognizerToFail: panGesture];
【讨论】:
以上是关于平移手势和滑动手势的主要内容,如果未能解决你的问题,请参考以下文章