Fade in and fade out UIView while driving

It’s easy enough to animate a view:

[UIView animateWithDuration:1.0 animations:^{theView.center = newCenter; theView.alpha = 0;} completion:^(BOOL finished){ [theView removeFromSuperview]; }]; 

The problem is that when I add it as a preview, I want it to fade out and already look like it is moving. Now he appears immediately, then moves and disappears.

So, I need to set the initial alpha to zero, fade quickly, as it moves, and then fade. Is this possible with UIView animation? Can't I have two competing animation blocks working on the same object?

+6
source share
2 answers

All you have to do is apply 2 animations to your back. Something like that::

 theView.alpha = 0; [UIView animateWithDuration:1.0 animations:^{ theView.center = midCenter; theView.alpha = 1; } completion:^(BOOL finished){ [UIView animateWithDuration:1.0 animations:^{ theView.center = endCenter; theView.alpha = 0; } completion:^(BOOL finished){ [theView removeFromSuperview]; }]; }]; 

So, in the 1st second it will appear while moving, and then in the next second it will disappear

Hope this helps

+12
source

Place start alpha = 0 outer animation block.

 theView.alpha = 0; [UIView animateWithDuration:1.0 animations:^{ theView.center = newCenter; theView.alpha = 1; } completion:^(BOOL finished){ // Do other things }]; 
+2
source

All Articles