// Create basic animation to rotate around the Y and Z axes
// CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
// transformAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
// transformAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(DEGREES_TO_RADIANS(0), 0, 1, 1)];
// transformAnimation.duration = 1.5;
// transformAnimation.autoreverses = YES;//栅格化图层
// transformAnimation.repeatCount = HUGE_VALF;
// transformAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
CABasicAnimation *translateAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
translateAnimation.fromValue = [NSValue valueWithCATransform3D:layer.transform];
translateAnimation.toValue = [NSNumber numberWithFloat:tx];
translateAnimation.duration = 1.5;
translateAnimation.autoreverses = YES;
translateAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
translateAnimation.repeatCount = HUGE_VALF;
[layer addAnimation:translateAnimation forKey:nil];
CATransform3DMakeRotation 旋转,翻转
该CATransform3DMakeRotatio
要水平(垂直)旋转45度,您可以使用下面的代码:
myTransform = CATransform3DMakeRotatio
要在Y轴上旋转相同的值:
myTransform = CATransform3DMakeRotatio
0.78 ,用在前面的例子,是由角度值经计算转化为弧度值。要把角度值转化为弧度值,可以使用一个简单的公式Mπ/180 。例如, 45π/180 = 45 ( 3.1415 ) / 180 = 0.7853 。如果你打算在你的程序里面一直都用角度值的话,你可以写一个简单的转化方法,以帮助保持您的代码是可以理解的:
double radians(float degrees) {
}
当你创建一个转换的时候,你将要调用这个方法:
myTransform = CATransform3DMakeRotatio
当变换(transformation)被创建好了以后,应用在你正在操作的层上。CALayer对象提供了一个transform属性来连接转换。层将执行分配给transform属性的转换:
imageView.layer.transform = myTransform;
当对象被显示后,将会显示应用到它的转换效果。在你的代码中,你任然把它当做是个2D对象。但是它根据提供的转换类型来渲染。