当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - 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 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];
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: