核心动画绕任意点旋转一层 [英] Core Animation rotating a layer around arbitrary point
问题描述
如何使用Core Animation围绕任意点旋转图层? (在我的情况下,一个点不在层内我想旋转)
我喜欢这样做而不改变锚点,因为除非我每次都得到错误我改变了锚点,它也改变了层的位置。
我尝试这样的,但它不工作:
[UIImageView beginAnimations:nil context:nil];
CATransform3D rotationTransform = CATransform3DIdentity;
rotationTransform = CATransform3DTranslate(rotationTransform,0.0,-100.0,0.0);
rotationTransform = CATransform3DRotate(rotationTransform,DegreesToRadians(180),
0.0,0.0,1.0);
rotationTransform = CATransform3DTranslate(rotationTransform,0.0,100.0,0.0)
shape1.layer.transform = rotationTransform;
[UIImageView commitAnimations];
看起来旋转轴在旋转过程中移动。
<我最终通过创建一个新的更大的图层,它的中心在我的旋转轴和设置图层我想旋转作为它的子图层。
然后我旋转较大的图层而不是子图层
How can I rotate a layer using Core Animation around an arbitrary point? ( In my case a point that is not inside the layer I want to rotate )
I prefer doing this without changing the anchor point, because unless I get something wrong every time I change the anchor point it also changes the position of the layer.
I tried something like that but it didn't work:
[UIImageView beginAnimations:nil context:nil];
CATransform3D rotationTransform = CATransform3DIdentity;
rotationTransform = CATransform3DTranslate(rotationTransform, 0.0, -100.0, 0.0);
rotationTransform = CATransform3DRotate(rotationTransform, DegreesToRadians(180),
0.0, 0.0, 1.0);
rotationTransform = CATransform3DTranslate(rotationTransform, 0.0, 100.0, 0.0)
shape1.layer.transform = rotationTransform;
[UIImageView commitAnimations];
It looks like the rotation axis is moving during the rotate.
I finaly did it by creating a new bigger layer with it's center at my rotation axis and setting the layer i want to rotate as it's sub layer.
Then I rotate the bigger layer instead of the sub layer
这篇关于核心动画绕任意点旋转一层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!