iPhone Programming Tricks and Traps

Basic Animation : set the animation properties (like duration) before setting the properties to be animated (this is where the animation is cast in stone).

Example : this fadeOut animation will last 1.5 s, as desired:

-(void) fadeOutMyImage {
 [UIView beginAnimations:nil context:nil];
 [UIView setAnimationDuration:1.5];
 myImageView.alpha = 0.0;
 [UIView commitAnimations];
}

Example : this fadeOut animation will last 0.2 s (the default), not 1.5 s as desired:

-(void) fadeOutMyImage {
 [UIView beginAnimations:nil context:nil];
 myImageView.alpha = 0.0;
 [UIView setAnimationDuration:1.5]; // WRONG, no effect
 [UIView commitAnimations];
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s