I have an image of globe which I want to rotate continuously around Y-axis. I also want to simulate it as an 3D rotation. I found some code using CABasicLayer and CALayer, but they rotate an image around Z-axis.
Asked
Active
Viewed 957 times
2 Answers
0
Try this code :
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"];

Anil
- 1,028
- 9
- 20
-
Xcode says unexpected @ in program for line no 2 and last line. – Geek May 09 '13 at 10:33
-
Thanks for your answer. But it does not exactly do what I want. I want the image (which is of a globe) to rotate like a real globe. May be I need many images of globe from different angle. But that is not my main concern. Is there any way to rotate like that? – Geek May 09 '13 at 10:43
-
Refer this : http://stackoverflow.com/questions/6080043/how-to-rotate-image-360-degrees-endlessly-using-iphone-sdk – Anil May 09 '13 at 11:04
0
I end up using this because I need different views of globes. All images are view of globe taken from different angle. Here there are just 5 images but in actual I'll use around 36 images, because images will have 10 as difference of angle. Thus, 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];

Geek
- 8,280
- 17
- 73
- 137