Mashhadi
Mashhadi

Reputation: 3024

How to animate and rotate an image?

Hi i am working on an iPhone application and i have to animate and rotate an image, Image is attached here enter image description here

now purpose of this image is that whenever any tap some where on iPad it will animate and will point towards that place.

Please help me to figure it out. Thanx

Upvotes: 2

Views: 8338

Answers (3)

Nithin M Keloth
Nithin M Keloth

Reputation: 1595

Try this -

CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
animation.duration = 10.0f;
animation.repeatCount = INFINITY;
[self.yourImage.layer addAnimation:animation forKey:@"SpinAnimation"];

Upvotes: 7

Ganzolo
Ganzolo

Reputation: 1394

To animate images view, you'll need to use CoreAnimation.

All you have to do is making UIImageView object with your image inside and then you'll manipulate directly the layer to animate.

There is 2 kind of animation with core animation :

  • Implicit animation (normally they are activate by default) : Everytime you change some setting on the layer (like position with [imageView.layer setPosition:CGPointMake...]) there should be an implicit animation with default parameters (Duration, AnimationCurve etc.)

  • Explicit animation : If you want to create more complex animations, you should use explicit animation, it will allow you to do complex things like moving, rotating and scaling some layer in the same time.

I encourage you to check the core animation programming guide

Upvotes: 3

Mudit Bajpai
Mudit Bajpai

Reputation: 3020

check this tutorial. It will really help you.

Upvotes: 3

Related Questions