How to make dissolve animation on changing views on iphone?

前端 未结 4 565
孤城傲影
孤城傲影 2020-12-28 20:07

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!

4条回答
  •  星月不相逢
    2020-12-28 21:03

    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];
                         }];
    }
    

提交回复
热议问题