iPad - 同时识别同一手势

发布于 2024-10-03 19:36:49 字数 434 浏览 0 评论 0原文

我需要一个用户可以绘制多个矩形的视图。现在我需要能够使用平移手势移动这些矩形。我遇到的问题是我可以使用平移手势识别器移动任何单个矩形,没有任何问题。现在,当我用 2 个手指平移 2 个矩形以同时移动时,它不起作用。

在我看来,问题是我为平移手势指定的目标/操作仅被触发一次。

我的观点采用 UIGestureRecognizerDelegate 并定义了这个委托方法:

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

提前致谢!

I need have a view where users can draw multiple rectangles. Now I need to be able to move those rectangles using a Pan gesture. The problem I am having is that I can move any single rectangle with the Pan gesture recognizer with no problem. Now when I use 2 fingers to Pan 2 rectangles to move simultaneously it doesn't work.

Seem to me that the problem is the target/action that I specified for the pan gesture gets fired only once.

My view adopts the UIGestureRecognizerDelegate and has defined this delegate method:

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

Thanks in advance!

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

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

发布评论

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

评论(1

迷乱花海 2024-10-10 19:36:49

通过创建一个方法,将手势识别器分别添加到每个创建的矩形视图中。

像这样

- (void)addGestureRecognizersToPiece:(UIView *)piece
{
  // Add the gesture recognizer to the piece here
}

您可以循环将手势识别器同时添加到所有片段,或者在创建每个矩形时,只需在创建矩形后触发此方法,并将其作为片段参数传递给此函数。

那应该有帮助。

Add gesture recognizer to each created rectangle view individually by making a method.

like this

- (void)addGestureRecognizersToPiece:(UIView *)piece
{
  // Add the gesture recognizer to the piece here
}

You can loop in to add the gesture recognizer to all the pieces simultaneously, or while u create each rectangle, just fire this method after creating the rectangle, and passing that as the piece parameter to this function.

That should help.

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