0

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?

iDev
  • 23,310
  • 7
  • 60
  • 85
Datenshi
  • 1,191
  • 5
  • 18
  • 56

2 Answers2

9

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;  
                 }];
 }
shannoga
  • 19,649
  • 20
  • 104
  • 169
  • Silly me.. That did work. But now another problem occured. I need to have _language.hidden = true in view didload. By having that hidden in the first place. I do not get the first animation properly, it gets show instantly. After that everything works just as expected. ideas? – Datenshi Nov 28 '12 at 08:25
  • Got it working by setting alpha in viewdidload to 0. Thank you for your answer ! – Datenshi Nov 28 '12 at 08:28
5

Your _Language.hidden is set as true and hence when it is animating, nothing will appear on the screen. You need to make it visible before animating. Set the hidden property to false and then show the animation. The reverse will work only for hiding when you add it in completion block.

_Language.hidden = false;
[UIView animateWithDuration:1.0 ...

and remove it from completion block,

completion:^(BOOL finished) {
                     }];
iDev
  • 23,310
  • 7
  • 60
  • 85
  • Thank you for your time answering, but I will accept @shannoga answer. As he was quicker in 3 seconds :) – Datenshi Nov 28 '12 at 08:29
  • 1
    In fact I was quicker by 10 seconds. :) You can verify by clicking on sorting by oldest tab(After accepting it wont show that). Anyways that is fine. Glad that it helped. – iDev Nov 28 '12 at 08:31