整个 UIView 的手势识别器

发布于 2024-10-07 22:29:24 字数 439 浏览 0 评论 0原文

我想找到一种方法来对整个 UIView 进行动画处理,其中包含一些 ui 组件。这是我的代码片段:

UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotatePiece:)];
[piece addGestureRecognizer:rotationGesture];
[rotationGesture release];

这里的“片段”是一个 uiview,我想旋转它,它工作得很好。但是,当我在其中添加一些其他 UI 组件(如 UIbutton)(片段视图)时,当用户触摸这些 UI 组件时,手势无法正确识别。本质上,我希望即使用户触摸子对象,父对象也能听到手势。

有什么想法吗?

I want to find a way to animate a whole UIView which contains some ui components within it. Here's my code snippet:

UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotatePiece:)];
[piece addGestureRecognizer:rotationGesture];
[rotationGesture release];

the "piece" is a uiview here which I want to rotate and it works perfectly fine. But when I add some other UI components (like UIbutton) inside it (piece view), gestures are not recognized properly when user touches on those UI components. Essentially, I want the parent to listen to the gestures even when user touches the child object.

Any ideas?

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

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

发布评论

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

评论(2

想你只要分分秒秒 2024-10-14 22:29:24

您只需将GestureRecognizer 添加到添加到视图的子视图中。正如在旋转片方法中一样,您可能只旋转原始视图,因此它可以正常工作。

you just need to addGestureRecognizer to your subviews you add to your view. As in the rotate piece method you might be rotating your original view only,so it will work fine.

放血 2024-10-14 22:29:24

您可以添加一个透明的 UIView 来覆盖整个区域,并在那里添加手势识别器。

You can add a transparent UIView to cover the whole area and add the gesture recognizer there.

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