popViewControllerAnimated: custom transition animation?

后端 未结 3 1197
醉话见心
醉话见心 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:36

    Joris Kluivers's answer in Swift 3 :

    CATransaction.begin()
    CATransaction.setDisableActions(true)
    
    let animation = CATransition()
    animation.type = kCATransitionFade
    self.navigationController?.view.layer.add(animation, forKey: "someAnimation")
    _ = self.navigationController?.popViewController(animated: false)
    
    CATransaction.commit()
    
    0 讨论(0)
  • 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).

    0 讨论(0)
  • 2020-12-17 00:46

    In iOS 7 above, you may want to look into UIViewControllerAnimatedTransitioning for presented view controllers, or UINavigationControllerDelegate method :

    - (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
    

    I have some sample code from another question for more info.

    0 讨论(0)
提交回复
热议问题