我将屏幕分成小块,然后为每个块设置动画以执行过渡:
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 实例重置前一层的属性有关。
有人对如何补救这种情况有建议吗?