开发者

How do I get rotate gesture to continue spin once state has ended?

开发者 https://www.devze.com 2023-02-07 05:48 出处:网络
I am using the code below to try and get my recognizer to continue spinning after the state has ended.It only seems to get one rotation no matter how high I set the value in the CGAffineTransformRotat

I am using the code below to try and get my recognizer to continue spinning after the state has ended. It only seems to get one rotation no matter how high I set the value in the CGAffineTransformRotate.

Any insight or suggestions would be appreciated.

Thanks.

if([(UIRotationGestureRecognizer*)recognizer state] == UIGestureRecognizerStateEnded) 
{开发者_运维百科
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:6.55];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, 1000000000);
    [UIView commitAnimations];
}


You might want to try to use a CABasicAnimation

- (void)rotate {

[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:2.0] forKey:kCATransactionAnimationDuration];

CABasicAnimation *animation;
animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:2 * M_PI];
animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
animation.delegate = self;
[recognizer.layer addAnimation:animation forKey:@"rotationAnimation"];

[CATransaction commit];
}

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)finished {
if (finished) 
    [self rotate];  
}

This will cause the rotation to continue until you specify to remove the animation.

There's more infomation and options in the CABasicAnimation Class Reference

0

精彩评论

暂无评论...
验证码 换一张
取 消