Animation code doesnt animate?
I have a view with which I have a button calling the following method. The view hides/shows but without any animation
- (void) displayEvent:(id)sender {
[UIView beginAnimations:nil开发者_StackOverflow context:NULL];
[UIView setAnimationDuration:2.5];
modal.hidden = !modal.hidden;
[UIView commitAnimations];
}
Any ideas?
There's no states in between hidden and non-hidden. How to animate?
To have the fade-in effect you should modify the alpha
property.
- (void) displayEvent:(id)sender {
BOOL wasHidden = modal.hidden;
modal.hidden = ! wasHidden;
modal.alpha = ! wasHidden; // wasHidden ? 0 : 1;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.5];
modal.alpha = wasHidden; // wasHidden ? 1 : 0;
[UIView commitAnimations];
}
精彩评论