- The first problem may cause by the wrong anchor point when using transform which can avoid using
CAAnimation
. - The second problem can be solved using
NSNumber
.
The code :
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotation.fromValue = [NSNumber numberWithFloat:0];
rotation.toValue = [NSNumber numberWithFloat:(arc4random() % 360 * M_PI / 180)];
rotation.duration = 5.0f;
rotation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
rotation.fillMode = kCAFillModeForwards;
rotation.removedOnCompletion = NO;
[self.imgRad.layer addAnimation:rotation forKey:@"rotatationRandom"];