我一直在玩弄 UINavigationController
的想法具有图像作为背景并且堆栈上的每个 View Controller 都将具有透明背景,因此 UINavigationController
的背景图像在所有这些中都可见。
我尝试以最明显的方式实现这一点(具有全屏图像的 Root View Controller 和具有透明背景的 View Controller ,但这会导致动画出现尴尬的问题)。
四处挖掘我发现 HotelTonight 应用程序设法实现了这一点。查看他们用户界面的记录。我做了:https://www.youtube.com/watch?v=qvynwhCj5oM&list=UUKnxsyMsRRRJs_Yw9GZVOFw
有人对实现这一点的正确路径有什么建议吗?
最佳答案
将 UIViewController 子类化以对其背景和导航 Controller 样式进行特定设置可能会更好。例如,在 UIViewController 子类的 viewDidLoad 方法中,将其背景设置为某个图像。您还可以使用它来设置导航栏的样式(barButtonItems 的某些颜色等)。然后,您创建的每个新 View Controller 都是蒙皮 View Controller 的子类。
如果您的背景是图像,当新的 View Controller 滑入旧 View Controller 的顶部时,您仍然会得到奇怪的动画效果;背景也会滑入。根据您希望如何自定义过渡动画,您可以做一些事情来在过渡期间使用 View 。 UIPresentationController 可能会提供一些解决方案来制作更自定义的动画过渡。
编辑:为了模拟 Hotel now 应用程序,我制作了一个带有图像作为背景的 UINavigationController,顶部的 Controller 具有清晰的背景。在插入时,我在 segue 发生时将第一个 Controller 的 alpha 设置为 0。返回时,我将 alpha 设置回 1。
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.view.alpha = 1;
}
-(void)didClickButton:(id)sender {
[UIView animateWithDuration:.25 animations:^{
self.view.alpha = 0;
}];
// the transition itself is a push segue defined in the storyboard
}
我相信酒店应用程序的背景很适合这种方法,因为它很暗。不确定它对于更明亮的应用程序或在 Controller 中包含大量内容的应用程序是否非常有效。
关于ios - UINavigationController 具有跨所有 ViewController 的统一背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26611185/