0

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

4

2 回答 2

0

我最终使用了它,因为我需要不同的地球仪视图。所有图像都是从不同角度拍摄的地球视图。这里只有 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];
于 2013-05-09T11:39:33.390 回答
0

试试这个代码:

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"];
于 2013-05-09T10:10:53.280 回答