开发者

3D Cube Problem! Part 1

开发者 https://www.devze.com 2023-03-11 23:02 出处:网络
I have created a 3D cube in iphone using CALayer\'s. Now I wanted to rotate that cube(CALayer) at 90˚ when user double taps on it.

I have created a 3D cube in iphone using CALayer's. Now I wanted to rotate that cube(CALayer) at 90˚ when user double taps on it.

I was able to rotate that cube(CALayer) to 90˚ once but when I double tap the cube(CALayer) is not rotating.

Here is the code that I used to rotate t开发者_如何学运维he cube(CALayer)

CATransform3D x = CATransform3DRotate(currentLayer.sublayerTransform, M_PI / 2, 0, 0, 1);
currentLayer.transform = x;

Can anyone help in this. What I'm doing wrong.


PS. For the people who are wondering how I got the degree sign then here is the trick

Option + K


its because you are not changing the angle of rotation .... to understand this lets say you are passing M_PI/2 each time to that method .... so CATransform3DRotate do not rotate it to next 90˚ rather it rotate the layer to the specified angle in this case its 90... so you are not getting any chage because it already at 90˚ ..... so to get correct result do this

static float angle = M_PI / 2;//dont make it static rather make it a global variable
angle += M_PI / 2;
CATransform3D x = CATransform3DRotate(currentLayer.sublayerTransform,angle, 0, 0, 1);
currentLayer.transform = x;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号