CABasicAnimation基于二个方向的旋转
1 CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
2 transformAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
3 transformAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(DEGREES_TO_RADIANS(85), 0, 1, 1)]; // 基于Y轴和Z轴同时旋转
4 transformAnimation.duration = 1.5;
5 transformAnimation.autoreverses = YES;
6 transformAnimation.repeatCount = HUGE_VALF;
7 transformAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
1 int tx = 0;
2 for (CALayer *layer in [rootLayer sublayers]) { // 循环每个子层
3 [layer addAnimation:transformAnimation forKey:nil]; // 每个子层都加入Y轴和Z轴旋转
4
5 CABasicAnimation *translateAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
6 translateAnimation.fromValue = [NSValue valueWithCATransform3D:layer.transform];
7 translateAnimation.toValue = [NSNumber numberWithFloat:tx];
8 translateAnimation.duration = 1.5;
9 translateAnimation.autoreverses = YES;
10 translateAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
11 translateAnimation.repeatCount = HUGE_VALF;
12 [layer addAnimation:translateAnimation forKey:nil];
13 tx += 35;
14 }