3

I am able to fade out my image successfully. When I try to fade it back in, it does not "fade" in... it just comes back abruptly. What am I doing wrong? Here is my code for fading it out and for trying to fade it back in:

Fading it out:

//Fade Out
Image.hidden = NO;
[UIView animateWithDuration:0.5 delay:1.0 options: UIViewAnimationOptionCurveEaseOut animations:^ {Image.alpha = 0;}
completion:^(BOOL finished){Image.hidden = YES;}];

This is what I use for trying to fading it back in; basically, I am doing the opposite... why doesn't it work?

//Fade In
Image.hidden = YES;
[UIView animateWithDuration:0.5 delay:1.0 options: UIViewAnimationOptionCurveEaseIn animations:^ {Image.alpha = 1;}
completion:^(BOOL finished){Image.hidden = NO;}];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
George Friday
  • 585
  • 1
  • 6
  • 22
  • I would use the `UIView.transtion` method instead--easier and has more options. Works from null image, or from image -> image. http://stackoverflow.com/a/9773674/111243 – SimplGy Jul 10 '15 at 20:30

3 Answers3

6

The image needs to be visible all the time while you're fading it in. You are animating the alpha property on a hidden image, and then showing it at the end. Correct would be:

Image.hidden = NO;
[UIView animateWithDuration:0.5 
                      delay:1.0 
                    options:UIViewAnimationOptionCurveEaseIn 
                 animations:^{ Image.alpha = 1; }
                 completion:^(BOOL finished){}
];
Seamus Campbell
  • 17,816
  • 3
  • 52
  • 60
2

You hide it first, so the fading is invisible. You need to set the alpha to 0 instead.

image.alpha = 0.0;
image.hidden = NO;
// do the animation to alpha => 1.0;

BTW, you should not use capitalized variable names.

Mundi
  • 79,884
  • 17
  • 117
  • 140
0

This is I think the shortest way of doing it. Create a UIView animation and commit it on your imageView.

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[myImageView setAlpha:0.0];
[UIView commitAnimations];
divyenduz
  • 2,037
  • 19
  • 38