如何使用CATransform3DRotate旋转UIImageView会产生像开门一样的效果?

ZYi*_*iOS 14 iphone core-animation catransform3d sliding-doors

我已阅读并试用这篇文章(使用Core Animation打开门效果)

我在我的应用程序中实现以下代码:

    CALayer *layer = threeHomeView.layer;
CATransform3D initialTransform = threeHomeView.layer.transform;
initialTransform.m34 = 1.0 / -900;

[UIView beginAnimations:@"Scale" context:nil];
[UIView setAnimationDuration:3];
layer.transform = initialTransform;
CATransform3D rotationAndPerspectiveTransform = threeHomeView.layer.transform;

rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform
                                                      , 40.0f * M_PI / 180.0f
                                                      , 0.0f
                                                      , 1.0f
                                                      , 0.0f);
layer.transform = rotationAndPerspectiveTransform;

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(threeHomeFlyOut)];
[UIView commitAnimations];  
Run Code Online (Sandbox Code Playgroud)

threeHomeView是一个UIImageView.

我的问题是:图像只能通过图像的中间垂直线旋转,但我想让它按图像的左垂直线旋转.

jtb*_*des 16

使用CATransform3DRotate就像你一样使用CATransform3DTranslate旋转边缘,就像我在这个答案中所做的那样.这里有一些摘录(您需要根据自己的需要对其进行修改):

CATransform3D t = CATransform3DIdentity;
t = CATransform3DTranslate(t, 0, -self.view.bounds.size.height/2, 0);
t = CATransform3DRotate(t, rec.scale * M_PI, 1, 0, 0);
t = CATransform3DTranslate(t, 0, -self.view.bounds.size.height/2, 0);
self.view.layer.transform = t;
Run Code Online (Sandbox Code Playgroud)