gpt4 book ai didi

ios - UINavigationController 的自定义动画推送无法正确呈现导航栏

转载 作者:可可西里 更新时间:2023-11-01 04:36:21 25 4
gpt4 key购买 nike

在自定义转场中,我有以下简单的转换:

- (void) perform {
UIViewController *src = (UIViewController *) self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;
[UIView transitionWithView:src.navigationController.view duration:1
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
[src.navigationController pushViewController:dst animated:NO];
}
completion:NULL];
}

内容 View 动画效果很好。然而,在执行动画时,顶部的导航栏布局困惑(按钮都挤在左上角,没有标题),只有在动画完成时才会弹出。任何人都知道我做错了什么以及如何解决它?谢谢!

最佳答案

解决了我的问题。考虑到 UINavigationController 如何工作以及如何与它管理的 UIViewController 交互,原始代码确实不正确。 (像我在 OP 中所做的令人讨厌的事情可以在旧的 SO 帖子中找到作为解决方案。)

这是对我有用的代码(有一个小问题):

- (void) perform {
UIViewController *src = (UIViewController *) self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;
[UIView transitionFromView:src.view
toView:dst.view
duration:1
options:UIViewAnimationOptionTransitionFlipFromBottom
completion:nil];
[UIView transitionFromView:src.navigationItem.titleView
toView:dst.navigationItem.titleView
duration:1
options:UIViewAnimationOptionTransitionFlipFromBottom
completion:nil];
[src.navigationController pushViewController:dst animated:NO];
}

Quib​​ble:这将使导航栏与内容 View 分开动画,因此您有两 block 翻转而不是整个屏幕。我最初尝试这样做:

    [UIView transitionFromView:src.navigationController.view
toView:dst.navigationController.view

但这失败了,因为 1) 目的地的 navigationController 属性在被推送到导航 Controller 之前甚至还没有设置,并且 2) 即使它是我指的是同一个 View !我忘记了

The view for a navigation controller is just a container for several other views, including a navigation bar, an optional toolbar, and the view containing your custom content...Although the content of the navigation bar and toolbar views changes, the views themselves do not...the navigation controller object builds the contents of the navigation bar dynamically using the navigation items (instances of the UINavigationItem class) associated with the view controllers on the navigation stack. To change the contents of the navigation bar, you must therefore configure the navigation items for your custom view controllers. (docs)

关于ios - UINavigationController 的自定义动画推送无法正确呈现导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11165820/

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