自定义iOS导航控制器动画:这是错误的吗?

自定义iOS导航控制器动画:这是错误的吗?,ios,objective-c,animation,uinavigationcontroller,pushviewcontroller,Ios,Objective C,Animation,Uinavigationcontroller,Pushviewcontroller,我被要求在两个UIViewControllers之间添加一个完全定制的转换,并提出了这个解决方案。这是可行的,但我不知道是否有更好/更优雅的方法 所谓完全自定义,我的意思是涉及修改第一个视图控制器子视图(移动它们,而不仅仅是淡入淡出或其他),能够更改持续时间,等等 我想知道两件事: 这能以任何方式打破吗?一些我可能忘记的问题,也许 你觉得这难看吗?如果是,有更好的解决方案吗 由于几行代码胜过千言万语,下面是一个非常简单的示例: // Considering that self.mainVie

我被要求在两个
UIViewController
s之间添加一个完全定制的转换,并提出了这个解决方案。这是可行的,但我不知道是否有更好/更优雅的方法

所谓完全自定义,我的意思是涉及修改第一个视图控制器子视图(移动它们,而不仅仅是淡入淡出或其他),能够更改持续时间,等等

我想知道两件事:

  • 这能以任何方式打破吗?一些我可能忘记的问题,也许
  • 你觉得这难看吗?如果是,有更好的解决方案吗
由于几行代码胜过千言万语,下面是一个非常简单的示例:

// Considering that self.mainView is a direct subview of self.view
// with exact same bounds, and it contains all the subviews

DCSomeViewController *nextViewController = [DCSomeViewController new];
UIView *nextView = nextViewController.view;

// Add the next view in self.view, below self.mainView
[self.view addSubview:newView];
[self.view sendSubviewToBack:newView];

[UIView animateWithDuration:.75f animations:^{
    // Do any animations on self.mainView, as nextView is behind, you can fade, send self.mainView to wherever you want, change its scale...
    self.mainView.transform = CGAffineTransformMakeScale(0, 0);

} completion:^(BOOL finished) {
    // Push the nextViewController, without animation
    [self.navigationController pushViewController:vc animated:NO];

    // Restore old 
    self.backgroundImageView.transform = CGAffineTransformIdentity;
}];
我仔细检查了一些我认为可能会出错的事情:

  • 推送之后,视图层次结构没有被破坏,一切看起来都很好,
    self.view
    遭受任何更改
  • 弹出时,
    nextView
    不再位于
    self.view

谢谢您的意见。

在ViewController之间进行转换有不同的方法。您的代码可以工作,但您可以实现更正式的方式

使用方法E
从ViewController:转换到ViewController:
查看教程:

或者您可以使用
UIViewControllerContextTransitioning
查看教程:和