【问题标题】:How to rotate a image (globe) around Y axis?如何围绕 Y 轴旋转图像(地球)?
【发布时间】:2013-05-09 09:45:39
【问题描述】:

我有一个地球图像,我想围绕 Y 轴连续旋转。我还想将其模拟为 3D 旋转。我发现了一些使用 CABasicLayer 和 CALayer 的代码,但是它们围绕 Z 轴旋转图像。

【问题讨论】:

    标签: objective-c ios6 uiimageview uiimage catransform3drotate


    【解决方案1】:

    试试这个代码:

    CABasicAnimation *rotateAnimation = [CABasicAnimation animation];
    rotateAnimation.keyPath = @"transform.rotation.z";
    rotateAnimation.fromValue = [NSNumber numberWithFloat:DegreesToRadians(0)];
    rotateAnimation.toValue = [NSNumber numberWithFloat:DegreesToRadians(360)];
    rotateAnimation.duration = 10;
    rotateAnimation.removedOnCompletion = NO;
    // leaves presentation layer in final state; preventing snap-back to original state
    rotateAnimation.fillMode = kCAFillModeForwards;
    rotateAnimation.repeatCount = 99;
    rotateAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    
    // add the animation to the selection layer. This causes it to begin animating
    [imageView.layer addAnimation:rotateAnimation forKey:@"rotateAnimation"];
    

    【讨论】:

    • Xcode 在第 2 行和最后一行的程序中显示意外 @。
    • 感谢您的回答。但它并不完全符合我的要求。我希望图像(它是一个地球仪)像一个真实的地球仪一样旋转。可能我需要许多不同角度的地球图像。但这不是我主要关心的问题。有什么办法可以这样旋转吗?
    【解决方案2】:

    我最终使用了它,因为我需要不同的地球仪视图。所有图像都是从不同角度拍摄的地球视图。这里只有 5 张图像,但实际上我会使用大约 36 张图像,因为图像会有 10 个角度差异。因此,360/10 = 36。

    UIImage *image = [UIImage imageNamed:@"globe.png"];
    UIImage *image1 = [UIImage imageNamed:@"globe1.jpeg"];
    UIImage *image2 = [UIImage imageNamed:@"globe2.jpeg"];
    UIImage *image3 = [UIImage imageNamed:@"globe3.jpeg"];
    UIImage *image4 = [UIImage imageNamed:@"globe4.jpeg"];
    
    NSArray *imageArray = [NSArray arrayWithObjects:image, image1, image2, image3, image4, nil];
    // set array of images, you want to cycle, to "animationImages" property.
    self.imageView.animationImages = imageArray;
    //duration of the animation-cycle
    self.imageView.animationDuration = 2.0;
    // 0 for endless repeation
    self.imageView.animationRepeatCount = 0;
    //starts the animation
    [self.imageView startAnimating];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-09
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 2018-08-02
      • 1970-01-01
      相关资源
      最近更新 更多