Reputation: 994
In my app i need to rotate a image between 0-90(deg)clockwise and vice-versa.for this first i am creating a imageview
self.needleImageView = [[UIImageView alloc]initWithFrame:CGRectMake(300,155, 15,150)];
self.needleImageView.layer.anchorPoint = CGPointMake(0.5,1.0);// Shift the Needle center point to one of the end points of the needle image.
self.needleImageView.backgroundColor = [UIColor clearColor];
self.needleImageView.image = [UIImage imageNamed:@"Arrow.png"];
[self.view addSubview:self.needleImageView];
With this code the image is coming in vertical direction.to get image in horizontal direction I am applying CGAffineTransformMakeRotation(-M_PI/2);
self.needleImageView.transform=CGAffineTransformMakeRotation(-M_PI/2);
After this to rotate the image i used following animation code //to rotate from 0-90 with autoreverse, after completing the animation to keep image in original position i have written the code in completion
[UIView animateWithDuration: 0.8f
delay: 0.0f
options: (UIViewAnimationOptionAutoreverse)
animations: ^{
self.needleImageView.transform = CGAffineTransformRotate(self.needleImageView.transform,M_PI/2);
}
completion: ^(BOOL finished) {
self.needleImageView.transform = CGAffineTransformRotate(self.needleImageView.transform,-M_PI/2);
}];
When i ran this code the image is coming in horizontal position,once i clicked on the animation button to apply animation the image rotation is starting from 270 deg-0 deg and vice versa..after animation image is positioning at 270 deg (vertically)
I want the image to be rotate between 0-90 deg only. Please run this code so you can understand my problem clearly Any help please...
Thanks in Advance
Upvotes: 0
Views: 1506
Reputation: 38259
This should solve the problem:
self.needleImageView1.transform = CGAffineTransformIdentity
//now animation
Note if u have UIViewAnimationOptionAutoreverse
then no use
for completion block
.
Upvotes: 0