UIScrollview,向下移动响应者链

发布于 2025-01-06 04:36:18 字数 286 浏览 0 评论 0原文

我会尽量保持简单。

我有一个 UIScrollview,附有大约 10 张图像。我目前拥有它,以便我可以触摸图像并将其在滚动视图上拖动。

我通过创建子类 UIImageview 并实现 TouchMoved 等来做到这一点。我仍然可以很好地滚动视图,但是当尝试拖动图像太快时就会出现问题。程序似乎首先检查视图是否正在滚动,然后在 UIImage 类中触发 TouchMoved。

无论如何,我可以切换这个,以便首先检查图像是否被触摸,然后如果没有将响应传递到滚动视图。

任何帮助都会很棒。谢谢。

I'll try and keep it simple.

I have a UIScrollview with around 10 images attached. I currently have it so that i can touch an image and drag it around on the scroll view.

I did this by creating the subclass UIImageview and implementing the touchesMoved etc. I can still scroll the view fine, but the problem comes when trying to drag an image too fast. It seems the program first checks if the view is being scrolled and then fires touchesMoved in the UIImage class.

Is there anyway I can switch this around so that the first check is if an image is touched, then if not pass the response onto the scrollview.

Any help would be great. Thanks.

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

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

发布评论

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

评论(2

葬花如无物 2025-01-13 04:36:18

最简单的方法是用一根手指移动图像,用两根手指滚动视图。

如果你使用的是 iOS 5,这非常简单:

self.scrollView.panGestureRecognizer.minimumNumberOfTouches = 2;

如果你想支持旧版本的 iOS,你必须做更多的工作:

for (UIGestureRecognizer *gesture in self.scrollView.gestureRecognizers){
  if ([gesture isKindOfClass:[UIPanGestureRecognizer class]]){
    ((UIPanGestureRecognizer *)gesture).minimumNumberOfTouches = 2;
  }
}

如果你想同时使用单指手势,有几种方法可以做吧。您可以将 UIPanGestureRecognizer 附加到每个图像视图。您可能需要使用 requireGestureRecognizerToFail: 消息告诉滚动视图自己的 UIPanGestureRecognizer 遵循图像视图识别器。

另一种方法是将滚动视图的 UIPanGestureRecognizer 委托设置为您创建的实现 gestureRecognizer:shouldReceiveTouch: 方法的对象。在该方法中,您可以检查触摸视图是否是您的图像视图之一。如果是,则返回 NO 以防止激活滚动视图的平移手势识别器。

The simplest way to do this would be use one finger to move an image, and two fingers to scroll the view.

If you're on iOS 5, this is super easy:

self.scrollView.panGestureRecognizer.minimumNumberOfTouches = 2;

If you want to support older versions of iOS, you have to do a little more work:

for (UIGestureRecognizer *gesture in self.scrollView.gestureRecognizers){
  if ([gesture isKindOfClass:[UIPanGestureRecognizer class]]){
    ((UIPanGestureRecognizer *)gesture).minimumNumberOfTouches = 2;
  }
}

If you want to use one-finger gestures for both, there are a few ways to do it. You could attach a UIPanGestureRecognizer to each image view. You might need to tell the scroll view's own UIPanGestureRecognizer to defer to the image view recognizers, using the requireGestureRecognizerToFail: message.

Another way would be to set the scroll view's UIPanGestureRecognizer's delegate to an object you create that implements the gestureRecognizer:shouldReceiveTouch: method. In that method, you can check whether the touch's view is one of your image views. If so, return NO to prevent the scroll view's pan gesture recognizer from activating.

耳钉梦 2025-01-13 04:36:18

你的问题让我有点困惑,但我假设你有一个 UIScrollView,里面有 10 个 UIImageView,你想拖动它们。

我的建议是使用附加到每个 UIIImageView 的手势识别器 (UIPanGestureRecognizer) 来实现拖动行为。我发现手势识别器是处理这种行为的更可靠的方法。

如果您不知道如何使用手势识别器,我可以发布一个简短的代码示例来演示如何拖动任何类型的 UIView。只需在评论中询问,我就会写它。

Your question is a little confusing to me but I will assume that you have a UIScrollView with 10 UIImageViews inside it which you want to drag around.

My suggestion would be to use a gesture recognizer (UIPanGestureRecognizer) attached to every UIIImageView in order to implement the dragging behaviour. I find gesture recognizers to be a more solid approach on this kind of behavior.

If you don't know how to work with gesture recognizers, I can post a short code example to demonstrate how you can drag any type of UIView. Just ask in a comment and I will write it.

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