Reputation: 9698
I am trying to animate the images of a UIButton
. The animation runs fine, but afterwards it always puts a gray tint on the button (as if it was being highlighted/selected).
Code:
NSArray *images = [[NSArray alloc] init];
images = [NSArray arrayWithObjects:
[UIImage imageNamed:IMAGE1],
[UIImage imageNamed:IMAGE2],
[UIImage imageNamed:IMAGE3],
[UIImage imageNamed:IMAGE4],
nil];
iconBobble.imageView.animationImages = images;
iconBobble.imageView.animationDuration = 1.5;
iconBobble.imageView.animationRepeatCount = 1;
[iconBobble.imageView startAnimating];
Upvotes: 3
Views: 1678
Reputation: 1483
adjustsImageWhenHighlighted
property will solve your problem.
This code will solve your problem....
-(IBAction)animateButton:(id)sender
{
[iconBobble setAdjustsImageWhenHighlighted:NO];
NSArray *images = [[NSArray alloc] init];
images = [NSArray arrayWithObjects:
[UIImage imageNamed:IMAGE1],
[UIImage imageNamed:IMAGE2],
[UIImage imageNamed:IMAGE3],
[UIImage imageNamed:IMAGE4],
nil];
float animationDuration = 1.5;
iconBobble.imageView.animationImages = images;
iconBobble.imageView.animationDuration = animationDuration;
iconBobble.imageView.animationRepeatCount = 1;
[iconBobble.imageView startAnimating];
[self performSelector:@selector(stopButtonAnimation) withObject:nil afterDelay:animationDuration];
}
-(void)stopButtonAnimation
{
[iconBobble.imageView stopAnimating];
}
This is working fine for me :-)
Upvotes: 8