2

我在检测UIImageViewself.view 内部的滑动时遇​​到问题。

当我应用它UISwipeGestureRecognizerself.view工作正常,但是当我尝试应用它时UIImageview它检测到错误的滑动​​方向。

代码:

{

//Swipe Up
swipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeUp:)];
swipeUpRecognizer.delegate = self;
swipeUpRecognizer = (UISwipeGestureRecognizer *)swipeUpRecognizer;
swipeUpRecognizer.numberOfTouchesRequired = 1;
swipeUpRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
[imageView addGestureRecognizer:swipeUpRecognizer];
[swipeUpRecognizer release];

//swipe Down
swipeDownRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeDown:)];
swipeDownRecognizer.delegate = self;
swipeDownRecognizer = (UISwipeGestureRecognizer *)swipeDownRecognizer;
swipeDownRecognizer.numberOfTouchesRequired = 1;
swipeDownRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
[imageView addGestureRecognizer:swipeDownRecognizer];
[swipeDownRecognizer release];

//swipe Left
swipeLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft:)];
swipeLeftRecognizer.delegate = self;
swipeLeftRecognizer = (UISwipeGestureRecognizer *)swipeLeftRecognizer;
swipeLeftRecognizer.numberOfTouchesRequired = 1;
swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[imageView addGestureRecognizer:swipeLeftRecognizer];
[swipeLeftRecognizer release];

//swipe Right
swipeRightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight:)];
swipeRightRecognizer.delegate = self;
swipeRightRecognizer = (UISwipeGestureRecognizer *)swipeRightRecognizer;
swipeRightRecognizer.numberOfTouchesRequired = 1;
swipeRightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[imageView addGestureRecognizer:swipeRightRecognizer];
[swipeRightRecognizer release];

}
4

1 回答 1

7

您必须在UIImageView. 使用下面的代码

imageView.userInteractionEnabled = YES;
于 2012-03-21T12:00:58.577 回答