Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make dissolve animation on changing views on iphone?

How to make dissolve animation on changing views in iphone?

Dissolve effect: one view is changing another without any movement.

Thanks a lot for the help!

like image 544
Dmitry Avatar asked Mar 01 '12 10:03

Dmitry


2 Answers

You can also use UIViewAnimationOptionTransitionCrossDissolve in ios5 and later...

[UIView transitionFromView:currentView
                    toView:nextView
                  duration:2
                   options:UIViewAnimationOptionTransitionCrossDissolve 
                completion:^(BOOL finished) {
                    [currentView removeFromSuperview];
                    }];
like image 59
Aravindhan Avatar answered Sep 28 '22 10:09

Aravindhan


The animation you're looking for is:

[UIView animateWithDuration: 1.0
                 animations:^{
                     view1.alpha = 0.0;
                     view2.alpha = 1.0;
                 }];

A more complete solution, using that animation might be:

- (void) replaceView: (UIView *) currentView withView: (UIView *) newView
{
    newView.alpha = 0.0;
    [self.view addSubview: newView];

    [UIView animateWithDuration: 1.0
                     animations:^{
                         currentView.alpha = 0.0;
                         newView.alpha = 1.0;
                     } 
                     completion:^(BOOL finished) {
                         [currentView removeFromSuperview];
                     }];
}
like image 40
Ashley Mills Avatar answered Sep 28 '22 09:09

Ashley Mills