我想執行一個無限360度旋轉動畫,所以編碼:CATransaction旋轉層360度奇怪
- (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裝置180度,所以相信層可以由0
到M_PI * 1
,M_PI * 2
旋轉...
但它原來是從0
到M_PI
,然後M_PI
到0
的旋轉。
我可以使它通過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"];
代碼以上360度完全旋轉層。
但是我對第一個實現感到困惑,爲什麼它會變得如此奇怪?
'rotate'的實現是什麼?它是否一次又一次地自我調用? –
是的,它每次都以當前的變換輪換M_PI。 – Bzmario