博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CATransform3DMakeRotation 旋转,翻转
阅读量:4109 次
发布时间:2019-05-25

本文共 2253 字,大约阅读时间需要 7 分钟。

  // 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 = [CABasicAnimationanimationWithKeyPath:@"transform.translation.x"];

translateAnimation.fromValue = [NSValuevalueWithCATransform3D:layer.transform];

translateAnimation.toValue = [NSNumbernumberWithFloat:tx];

translateAnimation.duration =1.5;

translateAnimation.autoreverses =YES;

translateAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];

translateAnimation.repeatCount =HUGE_VALF;

[layer addAnimation:translateAnimationforKey:nil];

CATransform3DMakeRotation 旋转,翻转

 
CATransform3D myTransform;
myTransform = CATransform3DMakeRotation(angle, x, y, z);

该CATransform3DMakeRotation函数创建了一个转变,将在三维轴坐标系以任意弧度旋转层。x-y-z轴的有个确定的范围(介于-1 和+1之间) 。相应的坐标轴指定的值告诉系统在该轴上旋转。例如,如果X轴是设置为-1或1 ,该对象将的X轴的方向上旋转,这意味着将把它垂直旋转。把这些值看做是插入在图像每个坐标轴上的秸秆(Think of these values as inserting straws through the image for each axis.)。如果秸秆插过x轴,图像将沿着秸秆垂直旋转。您可以使用坐标轴角度值创建更复杂的旋转。。对于大多数的用途,但是,值介于-1和+1已经足够。

要水平(垂直)旋转45度,您可以使用下面的代码:

myTransform = CATransform3DMakeRotation(0.78, 1.0, 0.0, 0.0);

要在Y轴上旋转相同的值:
myTransform = CATransform3DMakeRotation(0.78, 0.0, 1.0, 0.0);


0.78 ,用在前面的例子,是由角度值经计算转化为弧度值。要把角度值转化为弧度值,可以使用一个简单的公式Mπ/180 。例如, 45π/180 = 45 ( 3.1415 ) / 180 = 0.7853 。如果你打算在你的程序里面一直都用角度值的话,你可以写一个简单的转化方法,以帮助保持您的代码是可以理解的:

double radians(float degrees) {

    return ( degrees * 3.14159265 ) / 180.0;
}

当你创建一个转换的时候,你将要调用这个方法:

myTransform = CATransform3DMakeRotation(radians(45.0), 0.0, 1.0, 0.0);

当变换(transformation)被创建好了以后,应用在你正在操作的层上。CALayer对象提供了一个transform属性来连接转换。层将执行分配给transform属性的转换:

imageView.layer.transform = myTransform;

当对象被显示后,将会显示应用到它的转换效果。在你的代码中,你任然把它当做是个2D对象。但是它根据提供的转换类型来渲染。

转载地址:http://bjosi.baihongyu.com/

你可能感兴趣的文章
关于寄存器操作的指针问题
查看>>
makefile 的写法(转)
查看>>
两个个makefile例子的分析
查看>>
指针的赋值和初始化
查看>>
一些总结关于arm
查看>>
S3C2440系统中断(转)
查看>>
存储器
查看>>
stm32晶振不起振的问题
查看>>
存储器
查看>>
S3C2440 SDRAM内存驱动
查看>>
u-boot在jz2440上移植
查看>>
typedef __packed struct (结构体字节对齐)(转)
查看>>
关于无线PCB中 中50欧姆的特性阻抗的注意事项
查看>>
关于无线PCB中 中50欧姆的特性阻抗的注意事项
查看>>
STM32访问外部存储器的时序计算
查看>>
单链表的C实现
查看>>
_attribute_机制(转)
查看>>
LINUX 内核源文件介绍以及头文件介绍(转)
查看>>
ubuntu下sudo apt-get update Sources 404 Not Found [IP: 91.189.92.200 80]解决办法
查看>>
一步一步写万能makefile
查看>>