【发布时间】:2011-01-16 10:40:55
【问题描述】:
我是核心动画的新手,我想向左或向右旋转图像视图,但我希望它在 z 轴上旋转,这样它就可以看起来像圆形旋转。这是用于更多解释的图像
我想将图像旋转到内部图像视图中,这是两个图像视图。
我已尝试此代码,请有人应用此代码并更正代码。
-(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];
【问题讨论】:
-
我相信您图片中的滑块不使用 3D 的东西,而是使用顶部透明图像的 2D 滚动视图。
标签: objective-c iphone xcode core-animation uiimageview