【问题标题】:How to rotate UIImageView in 3d circular way?如何以 3d 圆形方式旋转 UIImageView?
【发布时间】: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


【解决方案1】:

您的问题与图片显示的不符。 Z 正在通过显示,负值离您更近。

您有 2 种可用的转换: - UIKit view.transform 级别的 2D - CALayers view.layer.transform 上的(伪)3D

使用 CATransform3DRotate 完成围绕 Z 的旋转变换

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-10
    相关资源
    最近更新 更多