问题描述
Flickr具有出色的设置"视图控制器(即使他们将关闭按钮放在错误的一侧!),我想知道如何实现类似的效果.
Flickr has a gorgeous Settings view controller (even if they put the close button on the wrong side!) and I want to know how I can achieve a similar effect.
请注意,导航控制器没有背景,但在其下方确实有阴影线以提供分隔.底层的模糊视图会填充整个显示,包括状态栏下方.
Notice the navigation controller does not have a background but it does have a shadow line underneath it to provide separation. The underlying blurred view fills the entire display including underneath the status bar.
您将如何实现-如何删除UINavigationBar
的背景?请注意,您不能简单地删除背景,因为滚动时该文本将出现在导航栏中.
How would you achieve that - how could you remove the background of the UINavigationBar
? Note you can't simply remove the background because when you scroll the text will appear in the navigation bar.
推荐答案
我能够通过首先通过扩展边缘选项阻止表格视图控制器的内容在顶部导航栏下方扩展来获得所需的行为.
I was able to obtain the desired behavior by first preventing the table view controllers' content from extending underneath the top navigation bar via the Extend Edges option.
要删除导航栏的外观,我将其制作为黑色半透明栏,然后为其背景图像添加了一个新的空白图像,如下所示:
To remove the navigation bar's appearance, I made it a Black Translucent bar, then added a new blank image for its background image like so:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
然后,我将导航控制器嵌入到容器视图中,该容器视图嵌入到常规视图控制器中,并设置了自动布局约束,以使容器视图填充视图.这使我可以在视图控制器中创建模糊效果,然后从表格视图控制器中删除背景色,以便可以在整个导航过程中看到该模糊效果.这是设置:
I then embedded the navigation controller into a container view which is embedded inside a regular view controller, with auto layout constraints set such that the container view fills the view. This allowed me to create the blur effect in the view controller, then remove the background color from table view controllers so that this blur effect can be seen throughout navigation. Here's the setup:
UIViewController
containerView
UINavigationController
UITableViewController ->
UITableViewController ->
UITableViewController...
这篇关于删除UINavigationBar背景并保留阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!