gpt4 book ai didi

ios - 自定义 iOS 导航 Controller 动画 : is this wrong?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:29 25 4
gpt4 key购买 nike

有人要求我在两个 UIViewController 之间添加一个完全自定义的转换,并想出了这个解决方案。它有效,但我不知道是否有更好/更优雅的方法。

通过完全自定义,我的意思是涉及修改第一个 View Controller subview (移动它们,而不仅仅是淡入淡出或其他),能够更改持续时间等。

我想知道两件事:

  • 这可以用任何方式分解吗?我可能忘记了一些问题?
  • 你觉得这很丑吗?如果是这样,是否有更好的解决方案?

因为几行代码胜过一千个单词,这里有一个非常简单的例子来理解这个想法:

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

我仔细检查了一些我认为可能出错的地方:

  • 推送后, View 层次结构没有被破坏,一切看起来都很好,self.view 承受任何变化
  • 弹出时,nextView 不再位于 self.view 中。

感谢您的意见。

最佳答案

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

使用方法 transitionFromViewController:toViewController:查看教程:http://www.objc.io/issue-1/containment-view-controller.html#transitions

或者您可以使用 UIViewControllerContextTransitioning 查看教程:http://www.objc.io/issue-5/view-controller-transitions.htmlhttp://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/

关于ios - 自定义 iOS 导航 Controller 动画 : is this wrong?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21021983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com