rotate a UIView around its center but several times

前端 未结 4 1427
忘了有多久
忘了有多久 2020-12-01 06:43

I\'m trying to rotate some UIView around its center, so the simple code goes something like (in pseudocode):

[UIView beginAnimations:@\"crazyRo         


        
4条回答
  •  孤城傲影
    2020-12-01 07:18

    As Brad Larson indicated, you can do this with a CAKeyframeAnimation. For instance,

    CAKeyframeAnimation *rotationAnimation;
    rotationAnimation = 
       [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
    
    rotationAnimation.values = [NSArray arrayWithObjects:
                                [NSNumber numberWithFloat:0.0 * M_PI], 
                                [NSNumber numberWithFloat:0.75 * M_PI], 
                                [NSNumber numberWithFloat:1.5 * M_PI], 
                                [NSNumber numberWithFloat:2.0 * M_PI], nil]; 
    rotationAnimation.calculationMode = kCAAnimationPaced;
    rotationAnimation.removedOnCompletion = NO;
    rotationAnimation.fillMode = kCAFillModeForwards;
    rotationAnimation.timingFunction = 
       [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    rotationAnimation.duration = 10.0;
    
    CALayer *layer = [viewToSpin layer];
    [layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
    

    You can control the duration of the total animation with the rotationAnimation.duration property, and the acceleration and deceleration (and calculation of steps in between) with the rotationAnimation.timingFunction property.

提交回复
热议问题