简体   繁体   中英

UIView rotation and Subview (Button) touch

I have a UIView and on this UIView I have 8 buttons. I need to rotate this UIVIew every time So I am using the code below:

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 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.

I have a sample project on github that shows how to do that:

iOS Core Animation demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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