简体   繁体   English

UIView旋转和Subview(按钮)触摸

[英]UIView rotation and Subview (Button) touch

I have a UIView and on this UIView I have 8 buttons. 我有一个UIView ,在这个UIView我有8个按钮。 I need to rotate this UIVIew every time So I am using the code below: 我每次都需要旋转此UIVIew因此我在使用以下代码:

CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 30;
fullRotation.repeatCount = MAXFLOAT;
[self.menuView.layer addAnimation:fullRotation forKey:@"360"];

It rotates my view properly, But I am unable to get touch on rotating buttons. 它可以正确旋转我的视图,但是我无法触摸旋转按钮。 Since the Parent view is rotating and the Buttons will also rotate, Touch isn't working. 由于父视图正在旋转,并且按钮也将旋转,因此触摸不起作用。 Thanks 谢谢

Because you rotate layer. 因为您旋转图层。 I think you can't do what you need, but try to use CGAffineTransform 我认为您无法完成所需的工作,但请尝试使用CGAffineTransform

CGAffineTransform transform //desired transform
[UIView animateWithDuration:time
                 animations:^{menuView.transform = transform;}];

and call it by timer. 并通过计时器调用它。

Normal view touches do not work correctly during an animation. 在动画过程中,普通视图触摸无法正常工作。 Animation only makes the views look like they are moving. 动画只会使视图看起来像在移动。 Their actual coordinates don't move. 它们的实际坐标不动。

If you want to support tapping on objects you will need to roll your own tap handling code at the superview level using the presentation layer's hitTest method. 如果要支持点击对象,则需要使用表示层的hitTest方法在超级视图级别滚动自己的点击处理代码。

I have a sample project on github that shows how to do that: 我在github上有一个示例项目,展示了如何执行此操作:

iOS Core Animation demo iOS核心动画演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM