6
我分離屏幕分成小塊,那麼動畫每個瓦片執行過渡:多CALayers動畫 - 填充模式
for (int x=0; x<number_of_x_splits; x++) {
for (int y=0; y<number_of_y_splits; y++) {
CGSize splitSize = CGSizeMake(screenBounds.width/number_of_x_splits, screenBounds.height/number_of_y_splits);
CATransformLayer *transformLayer = [CATransformLayer layer];
[transformLayer setFrame:CGRectMake(splitSize.width * x, splitSize.height * y, splitSize.width, splitSize.height)];
[transformLayer setPosition:CGPointMake((splitSize.width * x) + splitSize.width/2, (splitSize.height * y) + splitSize.height/2)];
... adding some sublayers to transformLayer...
CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
[rotate setDuration:5.0];
[rotate setFromValue:[NSNumber numberWithFloat:0]];
[rotate setToValue:[NSNumber numberWithFloat:M_PI]];
[rotate setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[rotate setTimeOffset:(1/(number_of_x_splits + number_of_y_splits)) * (x+y)];
[rotate setFillMode:kCAFillModeForwards];
[rotate setRemovedOnCompletion:NO];
[transformLayer addAnimation:rotate forKey:@"transform.rotation.y"];
}
}
的問題是,只有最後的CALayer鏈保持在最終位置。 我也曾嘗試設置CALayer的最終轉換值:
[transformLayer setTransform:CATransform3DMakeRotation(M_PI, 0, 1, 0)];
我想這有創造循環的CALayer的另一個實例重置以前層的性質有關。
任何人有一個建議如何彌補這種情況?
確實!!解決它。從現在開始沒有TimeOffset!非常感謝! – Nimrod7 2012-07-24 07:15:13
beginTime應該是CACurrentMediaTime()+ yourDelay,除非動畫是動畫組的一部分。在這種情況下,它從基本時間值開始使用0,從父動畫組的開始處開始。 – 2013-02-28 22:12:56
@DuncanC很好的一點。 – 2013-03-01 07:24:13