popViewControllerAnimated: custom transition animation?

后端 未结 3 1385
醉话见心
醉话见心 2020-12-17 00:33

Yes, I have looked for an answer already. None of the solutions work, except one that doesn\'t give the option for a fade transition, only flip or curl.

Like this:

3条回答
  •  清酒与你
    2020-12-17 00:41

    For this type of transition I would really recommend a modal view controller, thats the way the system was designed.

    But if you insist on using the navigation controller there is a way, though somewhat ugly.

    [CATransaction begin];
    [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
    
    CATransition *transition = [CATransition animation];
    [transition setType:kCATransitionFade];
    [self.navigationController.view.layer addAnimation:transition forKey:@"someAnimation"];
    
    [self.navigationController popViewControllerAnimated:YES];
    [CATransaction commit];
    

    The CATransaction will disable all standard animations. The CATransition adds a fade transition to the navigation controller layer when views are swapped (in this case removing the viewcontroller view that is popped).

提交回复
热议问题