平移手势和轻扫手势

时间:2014-03-04 05:18:31

标签: ios iphone objective-c ios7

在我的项目中,我需要一个向左移动的滑动手势动作,我需要一个平移手势动作的顶部底部方向。当我放置两个手势时,只有pan手势正在调用。有人有解决方案吗?

 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];

我正在使用此代码

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
[self.view addGestureRecognizer:edgePanGesture];

2 个答案:

答案 0 :(得分:1)

[panGesture requireGestureRecognizerToFail:rightSwipe];
[panGesture requireGestureRecognizerToFail:leftSwipe];

答案 1 :(得分:1)

如果其他手势识别器未执行,请使用requireGestureRecognizerToFail:识别手势。

[rightSwipe requireGestureRecognizerToFail: panGesture];
[leftSwipe requireGestureRecognizerToFail: panGesture];