I’m using CAKeyframeAnimation.
-(IBAction)start:(id)sender {
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(600, 150)];
[path addLineToPoint:CGPointMake(600, 300)];
[path addLineToPoint:CGPointMake(450, 300)];
[path addLineToPoint:CGPointMake(450, 150)];
[path addLineToPoint:CGPointMake(600, 150)];
CAKeyframeAnimation *move = [CAKeyframeAnimation animationWithKeyPath:@"position"];
move.path = path.CGPath;
move.duration = 6.0f;
move.repeatCount = 100;
[testButton.layer addAnimation:move forKey:@"move"];
I need to make possible to use button while it moving.
Also I tried use touches detection but its only working with button while it stop.
Is it possible?
Thanks.
Really! you want the user to press the button while it is animating? People prefer to turn off interaction during animation. But anyway it this is your interaction then so be it. Have you tried –
[yourButton setUserInteractionEnabled:TRUE];Normally during any
UIViewanimations we need to simply putUIViewAnimationOptionAllowUserInteractionas the animation option and thats it. Since you have gone more deeper in using CoreAnimation and layers, not sure what options make it work there. Please let us know how it works out for you…UPDATE: This problem looked interesting to me. So I was just trying this out in Xcode. Here is what I found. To hit a moving button, you need to do hit testing on the button’s
.layer.presentationLayerproperty (needQuartzCorefor this) in your view controller.Internally, The animation is just eye candy. The animation lags behind the actual movement of the view. The button is already at the destination point when the animation starts. You just see a movie of the view/button moving. If you want a button to be clickable during the animation, you’ll have to make the animation yourself.
So the coe would be like this-