示例代碼是here。隱式屬性動畫不適用於CAReplicatorLayer?
用隱式屬性動畫替換顯式屬性動畫後,動畫被打破。
明確動畫:
-(void)animate:(id)sender {
...
//Transform Animation
animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.fromValue = [NSValue valueWithCATransform3D: CATransform3DIdentity];
animation.toValue = [NSValue valueWithCATransform3D: t];
animation.duration = 1.0;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBoth;
[subLayer addAnimation:animation forKey:@"transform"];
//Opacity Animation
animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:0.0];
animation.duration = 1.0;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBoth;
[subLayer addAnimation:animation forKey:@"opacity"];
...
}
-(void)reset:(id)sender {
...
//Transform Animation
animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.fromValue = [NSValue valueWithCATransform3D: t];
animation.toValue = [NSValue valueWithCATransform3D: CATransform3DIdentity];
animation.duration = 1.0;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBoth;
[subLayer addAnimation:animation forKey:@"transform"];
//Opacity Animation
animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:1.0];
animation.duration = 1.0;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBoth;
[subLayer addAnimation:animation forKey:@"opacity"];
...
}
隱動畫:
-(void)animate:(id)sender {
...
//Transform Animation
[CATransaction setAnimationDuration:1];
subLayer.transform = t;
//Opacity Animation
[CATransaction setAnimationDuration:1];
subLayer.opacity = 0;
...
}
-(void)reset:(id)sender {
...
//Transform Animation
[CATransaction setAnimationDuration:1];
subLayer.transform = CATransform3DIdentity;
//Opacity Animation
[CATransaction setAnimationDuration:1];
subLayer.opacity = 1;
...
}
爲什麼?
顯然,我使用隱式事務。 – an0
顯然,我錯了,確實發現了一個提示,但無法測試手頭沒有OSX的b/c。顯然,你不知道答案B/C你否則不會問。現在我已經研究了一些,並找到了適用於我的機器的答案。 –
順便說一句,CATransaction的開始/提交併不會使動畫顯式化,只要不創建動畫並將其添加到圖層中,它仍然是隱式動畫。顯然,我應該加上:-) –