Remove UINavigationBar background and preserve shadow

送分小仙女□ 提交于 2019-12-13 03:03:32

问题


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.

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.


回答1:


Use a UILabel instead of navigation bar (they probably do the samething, judging from the height of the bar). The shadow line is just another view, with appropriate background color.




回答2:


Hiding the background image indeed shows the text underneed when scrolling. One way I imagine you can try to achieve this is is not extending the ScrollView to under the NavBar? Another would be to create a background using a snapshot of the initial view, and using this as the background image for the navBar - hope that helps.




回答3:


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...


来源:https://stackoverflow.com/questions/27142416/remove-uinavigationbar-background-and-preserve-shadow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!