Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redrawing a UIView with a fade animation?

In TwUI, there is a method called redraw on TUIView. It forces the view to redraw, but it also comes with a free fading animation between the old and new state of the view.

I'm wondering if something like that is possible in a normal UIView. Basically, how can I redraw the view (setNeedsDisplay) with a fading animation between the old and the new states?

like image 422
sudo rm -rf Avatar asked Dec 19 '11 20:12

sudo rm -rf


2 Answers

Use +[UIView transitionWithView:duration:options:animations:completion:] with the UIViewAnimationOptionTransitionCrossDissolve option, and inside the animation block, force the view's layer to redraw its contents immediately.

[myView setNeedsDisplay];
[UIView transitionWithView:myView duration:1
    options:UIViewAnimationOptionTransitionCrossDissolve
    animations:^{
        [myView.layer displayIfNeeded];
    } completion:nil];
like image 87
rob mayoff Avatar answered Sep 18 '22 05:09

rob mayoff


How about using a cross-dissolve UIView transition?

[UIView transitionWithView:aView 
                  duration:TIME_INTERVAL 
                   options:UIViewAnimationOptionTransitionCrossDissolve 
                animations:^{
                    // Change the view's state
                } 
                completion:^(BOOL finished) {
                    // Completion block
                }];
like image 40
sho Avatar answered Sep 20 '22 05:09

sho