为什么UIPinchGestureRecognizer不会被调用,而scrollViewDidEndZooming会被调用?

发布于 2024-11-25 04:36:19 字数 985 浏览 0 评论 0原文

我有一个 UIViewController,它使用 UIScrollView,在该 Scrollview 中它有一个 UIImageView。

我想识别捏合并相应地缩放。我不需要缩放,我只需要显示不同的图像。

它看起来很像这个问题:UIView UIPinchGestureRecognizer问题

我尝试了几件事:

  • 设置contentMode将 UIViewContentModeScaleAspectFit

  • 设置multipleTouchEnabled = YES

  • 设置userInteractionEnabled = YES

然而,它仍然不能总是捕获捏合事件。

以下是我如何将手势分配给视图,非常简单:

   UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(zoomPinch:)];
    [MediaScroller addGestureRecognizer:pinchRecognizer];
    [pinchRecognizer release];

此外,我确实注意到我的委托调用了 scrollViewDidEndZooming ,但比例变量始终为 1.0。怎么可能呢?

scrollViewDidEndZooming 始终被调用,而捏合方法 (zoomPinch) 并不总是被调用。有什么原因会发生这种情况吗?我该如何解决它? :)

I have a UIViewController, which uses a UIScrollView and within that Scrollview it has a UIImageView.

I want to recognize a pinch and zoom accordingly. I don't need to scale, i just need to show a different image.

It pretty much looks like this question: UIView UIPinchGestureRecognizer problem

I have tried several things:

  • set contentMode to UIViewContentModeScaleAspectFit

  • set multipleTouchEnabled = YES

  • set userInteractionEnabled = YES

And yet, it still not always catches the pinching event.

Here is how I assign the gesture to the view, pretty straightforward:

   UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(zoomPinch:)];
    [MediaScroller addGestureRecognizer:pinchRecognizer];
    [pinchRecognizer release];

Also, I do notice that the scrollViewDidEndZooming is called of my delegate, but the scale variable is always 1.0. How can that be?

The scrollViewDidEndZooming is always called, while the pinch method (zoomPinch) is not always called. Any reasons why that would happen? And how can I fix it? :)

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

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

发布评论

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

评论(1

只为守护你 2024-12-02 04:36:19

我相信您需要在您的识别器委托中实现这一点:

pinchRecognizer.delegate = self;

然后,在自身类上:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
     return YES;
}

由于该类已经识别捏合(用于缩放),因此您可能需要启用多个捏合处理程序。

I believe you need to implement this in your recognizer delegate:

pinchRecognizer.delegate = self;

then, on self class:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
     return YES;
}

As the class already recognizes pinch (for zoom), maybe you need to enable to have more than one handler for pinch.

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