如何使用CATransform3DRotate旋转UIImageView会产生像开门一样的效果? [英] How to rotate an UIImageView with CATransform3DRotate make an effect like Door Opening?

查看:172
本文介绍了如何使用CATransform3DRotate旋转UIImageView会产生像开门一样的效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读并试用此文章(使用核心动画打开门效果)

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

And I implement following code in my app:

    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];  

threeHomeView是一个UIImageView。

threeHomeView is an UIImageView.

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

MY QUESTION IS: the image can only rotate by middle vertical line of the image, but I want it to rotate by left vertical line of the image.

推荐答案

使用 CATransform3DRotate 就像你和 CATransform3DTranslate一样/ code>围绕边缘旋转,就像我在这个答案。这里有一些摘录(您需要根据自己的需要对其进行修改):

Use CATransform3DRotate like you did in combination with CATransform3DTranslate to rotate around the edge, like I did in this answer. Here's a little excerpt (you will need to modify this for your own uses):

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;

这篇关于如何使用CATransform3DRotate旋转UIImageView会产生像开门一样的效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆