0
我有一个地球的图像,我想围绕Y轴连续旋转。我也想把它模拟成3D旋转。我发现了一些使用CABasicLayer和CALayer的代码,但它们围绕Z轴旋转图像。如何绕Y轴旋转图像(球体)?
我有一个地球的图像,我想围绕Y轴连续旋转。我也想把它模拟成3D旋转。我发现了一些使用CABasicLayer和CALayer的代码,但它们围绕Z轴旋转图像。如何绕Y轴旋转图像(球体)?
试试这个代码:
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"];
我最终使用,是因为我需要的地球仪的不同意见。所有图像都是从不同角度拍摄的地球视图。这里只有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];
Xcode在第2行和最后一行的程序中表示意外的@。 – Geek 2013-05-09 10:33:00
查看编辑答案 – Anil 2013-05-09 10:34:51
感谢您的回答。但它并不完全符合我的要求。我希望图像(这是一个地球仪)像一个真正的地球仪一样旋转。可能是我需要从不同的角度来看地球的许多图像。但那不是我主要关心的问题。有没有什么办法像这样旋转? – Geek 2013-05-09 10:43:30