Search code examples
iosobjective-ccocoa-touchblock

UIView animation hide and show


I am begining to use UIView animation. And can't get such code working properly. Here is what i have

if(_Language.hidden == true)
{
    [UIView animateWithDuration:1.0
                          delay:0.0
                        options:UIViewAnimationCurveEaseInOut
                     animations:^ {
                        _Language.alpha = 1.0;
                     }
                     completion:^(BOOL finished) {
                         _Language.hidden = false;
                     }];
}
else
{
    [UIView animateWithDuration:1.0
                          delay:0.0
                        options:UIViewAnimationCurveEaseInOut
                     animations:^ {
                         _Language.alpha = 0.0;
                     }
                     completion:^(BOOL finished) {
                         _Language.hidden = true;
                     }];
}

This code works in such way. Hide animation works as expected. But show animation just waits 1 sec, and pops the object without any transition. Can anyone tell me what I am missing here?


Solution

  • You are changing the hidden attribute to true only after the animation is over, so it doesn't appear until the animation is completed. you should do it before the animation begins :

    if(_Language.hidden == true)
     {
     _Language.hidden = false;
    [UIView animateWithDuration:1.0
                          delay:0.0
                        options:UIViewAnimationCurveEaseInOut
                     animations:^ {
                        _Language.alpha = 1.0;  
                     }];
     }