UIScrollView 与 UIPinchGesture

发布于 2025-01-07 17:32:56 字数 391 浏览 5 评论 0原文

我有一个 UIScrollView ,上面附加了一个 UIPinchGesture 。我的问题是,如果我执行捏合手势,它会移动 UIScrollView,并且在 NSLogging UIScrollView 的 X/Y 时可以看到这一点。我想知道是否有人有任何想法来防止滚动视图上发生这种情况?

我已经设置了最小和最大缩放比例:

[scrollView setMaximumZoomScale: 1.0];
[scrollView setMinimumZoomScale: 1.0];

此外,我还对 UIScrollView 进行了子类化并实现了 TouchBegan 和 TouchEnded,但我不确定如果使用 2 个手指,我将如何忽略滚动视图上的触摸?

请指教。

I have a UIScrollView with a UIPinchGesture attached to it. My problem is though if I do a pinch gesture it moves the UIScrollView's and can see this when NSLogging the UIScrollView's X/Y. I was wondering if anyone has any ideas to prevent this happening on the scrollview?

I already set the minimum and maximum zoom scale:

[scrollView setMaximumZoomScale: 1.0];
[scrollView setMinimumZoomScale: 1.0];

Also I have subclasses the UIScrollView and implemented the touchesBegan and touchesEnded but I am unsure how I would ignore a touch on the scrollview if 2 fingers are used?

Please advise.

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

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

发布评论

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

评论(1

夏末染殇 2025-01-14 17:32:56

您可以明智地使用 ScrollEnabled 属性。

还要取消使用两根手指时的触摸,

 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches];

    if ([allTouches count] > 1)
    {
        [self touchesCancelled:touches withEvent:event];
    }
    else
    {
        //pass touch.
    }
}

you can wisely use ScrollEnabled property.

Also to cancel touch when two fingers are used,

 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches];

    if ([allTouches count] > 1)
    {
        [self touchesCancelled:touches withEvent:event];
    }
    else
    {
        //pass touch.
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文