How to rotate a image (globe) around Y axis?

961 Views Asked by At

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.

2

There are 2 best solutions below

3
Anil On

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"];
0
Geek On

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];