I want to perform an infinite 360 degrees rotation animation, so I coded:
- (void)rotate
{
__weak typeof(self) weakSelf = self;
[CATransaction begin];
[CATransaction setDisableActions:NO];
[CATransaction setCompletionBlock:^{
[weakSelf rotate];
}];
[CATransaction setAnimationDuration:1.0];
[CATransaction setAnimationTimingFunction:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
self.squareLayer.transform = CATransform3DRotate(self.squareLayer.transform, M_PI, 0, 0, 1);
[CATransaction commit];
}
M_PI means 180 degrees, so I believe the layer can be rotated from 0
to M_PI * 1
, M_PI * 2
...
But it turns out to be an rotation from 0
to M_PI
, then M_PI
to 0
.
I can make it through a CABasicAnimation
:
CABasicAnimation *animatin = [CABasicAnimation animationWithKeyPath:@"transform"];
animatin.duration = 1.0;
animatin.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0, 0, 0, 1)];
animatin.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0, 0, 1)];
animatin.repeatCount = HUGE_VALF;
animatin.fillMode = kCAFillModeForwards;
[self.squareLayer addAnimation:animatin forKey:@"a"];
Codes above rotate the layer 360 degrees perfectly.
But I am really confused about the first implementation, why it rotates so strange?