Objective-C CALayer UIView real rotation

柔情痞子 提交于 2019-12-02 06:52:41

问题


I'm trying to rotate a UIView object like shown on the image below http://i.piccy.info/i7/f8ff7fe488c7c492e6ff6a689bc9cdeb/1-5-2127/60800682/rotation.png

I'm trying to use the CALayer's transform but I get something like this: http://i.piccy.info/i7/bbb672b058fdfdd251cc90f1ce2b9c1f/1-5-2128/9488743/rotate2.png


回答1:


If I understand correctly, you want to title the view backwards (into the screen) an should be able to achieve it something like this:

float distance = 50;

CATransform3D basicTrans = CATransform3DIdentity;
basicTrans.m34 = 1.0 / -distance;
view.layer.transform = CATransform3DRotate(basicTrans, M_PI_4, 1.0f, 0.0f, 0.0f);

To achieve this effect you need to manipulate one of the transformation values directly (m34). The lower distance gets, the stronger the effect gets. Then you can do the rotation transformation around the x axis (to tilt), in this case PI/4 or 45 degrees. You can calculate arbitrary values pi using degrees * M_PI / 180.0.



来源:https://stackoverflow.com/questions/8271416/objective-c-calayer-uiview-real-rotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!