整个 UIView 的手势识别器
我想找到一种方法来对整个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需将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.
您可以添加一个透明的 UIView 来覆盖整个区域,并在那里添加手势识别器。
You can add a transparent UIView to cover the whole area and add the gesture recognizer there.