我是核心动画的新手我想要向左或向右旋转图像视图,但我想让它在z轴上旋转,这样它就像是一个圆形旋转。这是一个图像以获得更多解释
alt text http://i45.tinypic.com/e9avx2.png
我想将图像旋转到内部图像视图,这是两个图像视图。
我试过这段代码请有人申请并更正代码。
-(void)Rotate
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3.0];
CATransform3D t1 = CATransform3DIdentity;
if(goingCW)
{
t1 = CATransform3DRotate(t1, radians(90), 0, 1, 0);
t1 = CATransform3DTranslate(t1, CUBESIZE/2, 0, 0);
t1 = CATransform3DRotate(t1, radians(90), 0, 1, 0);
t1 = CATransform3DTranslate(t1, CUBESIZE/2, 0, 0);
t1 = CATransform3DRotate(t1, radians(90), 0, 1, 0);
t1 = CATransform3DTranslate(t1, CUBESIZE/2, 0, 0);
CATransform3D moveTransform = CATransform3DRotate(t1, 0.0, -1.0, 0.0, 0.0);
[InnerView.layer setTransform:moveTransform];
NSLog(@"Going Left");
}
else
{
NSLog(@"Going Right");
t1 = CATransform3DRotate(t1, radians(90), 0, 1, 0);
t1 = CATransform3DTranslate(t1, CUBESIZE, 0, 0);
CATransform3D moveTransform = CATransform3DRotate(t1, 0.0, 1.0, 0.0, 0.0);
[InnerView.layer setTransform:moveTransform];
}
goingCW=!goingCW;
[UIView commitAnimations];
}
使用viewDidLoad或applicationDidFinishLaunching中的计时器调用此方法
goingCW = YES; // change this to NO to make it start rotating CCW instead A bool flag in header file.
NSTimer *timer=[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(Rotate) userInfo:nil repeats:YES];
答案 0 :(得分:1)
您的问题与图片显示的内容不符。 Z正在显示,负值更接近你。
您有两种可用的转换: - UIKit view.transform级别的2D - CALayers view.layer.transform
上的(伪)3D使用CATransform3DRotate
完成Z周围的旋转变换