UIView 内 UIImageview 上的 UISwipeGestureRecognizer 检测到错误的滑动​​?

发布于 2024-12-16 20:08:50 字数 2015 浏览 0 评论 0原文

我在检测 self.view 内的 UIImageView 上的滑动时遇​​到问题。

当我在 self.view 上应用 UISwipeGestureRecognizer 时,它工作正常,但是当我尝试在 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];

}

I am having problem with detecting swipe on UIImageView which is inside self.view.

When I apply UISwipeGestureRecognizer on self.view it works fine, but when i try to apply same on UIImageview it detects wrong swipe direction.

Code:

{

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小霸王臭丫头 2024-12-23 20:08:50

您必须在 UIImageView 上启用用户交互。使用下面的代码

imageView.userInteractionEnabled = YES;

You have to enable the user interaction on your UIImageView. Use the code below

imageView.userInteractionEnabled = YES;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文