In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the impact of the iOS navigation bar on the controller view". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Preface
When we set some properties of the navigation bar, it will cause the layout of the controller View to start from the bottom of the navigation bar instead of from the (0Magne0) point of the window. At this time, the frame of the View obtained in the viewDidLoad does start from (0Magne0), and the final actual frame of the view can be obtained only in the viewDidAppear.
Some attributes
Before you understand UINavigationBar, it is necessary to understand some of the properties of UINavigationBar
/ / default default translucent black black open var barStyle: UIBarStyle// bottom shadow horizontal line, default nil// official interpretation also involves a method to set the background image-setBackgroundImage:forBarMetrics:open var shadowImage: UIImage?// 7.0has changed. To modify the bar background color, please use-barTintColoropen var tintColor: UIColor default is nil bar background color open var barTintColor: UIColor?/// more influential attributes see below Whether it is translucent open var isTranslucent: Bool / / Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent
Some conditions
/ / the current controller is not tableviewcontrollerself.view.backgroundColor = .cyanself.tableView.backgroundColor = .redself.navigationItem.title = "rootVC title" tableView.frame = view.bounds
1.1 default navigation bar with translucent effect
At this point, view and tableview and navigation bar layout
1 view full screen layout
2 tableview is laid out from the bottom of the navigation bar by default
3. Navigation bar translucent
Details: the _ UIVisualEffectBackdropView attribute in the navigation bar turns red, that is, the background color of the tableview.
1.2 at this point, you can add code if you want tableview to start layout from the top.
If # available (iOS 11.0 iOS *) {self.tableView.contentInsetAdjustmentBehavior = UIScrollView.ContentInsetAdjustmentBehavior.never;} else {self.automaticallyAdjustsScrollViewInsets = false;}
The amazing thing is that if tableview is laid out from the top, the _ UIVisualEffectBackdropView property in the navigation bar will become the default white again.
2 set the navigation bar isTranslucent property
IsTranslucent defaults to true after 6. 0.
If set to false
Self.navigationController?.navigationBar.isTranslucent = false
Layout at this time
1 view layout from the bottom of the navigation bar
2 tableview layout from view (0d0)
3 the navigation bar is opaque _ UIBarBackground is white by default
3.1Setting barTintColor
Self.navigationController?.navigationBar.isTranslucent = trueself.navigationController?.navigationBar.barTintColor = UIColor.purple
The layout is the same as the default
1 view from (0d0) layout
2 tableview layout from the bottom of the navigation bar 3 navigation bar translucency
The difference is that UIVisualEffectView adds an extra _ UIVisualEffectSubview to display our custom background color.
The other two _ UIVisualEffectSubview and _ UIVisualEffectBackdropView view are used to achieve translucency.
3.2 set the isTranslucent = false attribute on the basis of barTintColor
The result is the same as in 2. The difference is
_ UIBarBackground has become our custom color.
4.1Setting setBackgroundImage
Set up a solid color picture
Self.navigationBar.setBackgroundImage (UIColor.mm_colorImgHex (color_vaule: hex,alpha: 1), for: UIBarPosition.any, barMetrics: .default)
Layout at this time
1 view layout view--- from the bottom of the navigation bar (0.0,88.0,414.0, 808.0)
2 tableview from (0d0) layout
3 the navigation bar is opaque
At this point, the isTranslucent property of the print navigation bar is false, which means that if setBackgroundImage is called, isTranslucent will be set to false by default.
Translate-Optional (false)
4.2 We modified isTranslucent in case of 4.1
Change isTranslucent to true in viewWillAppear
Layout at this time
1 view full screen layout
2 tableview layout starts from the bottom and top of the navigation bar
3 the navigation bar is transparent
The BackgroundImage transparency in printing our _ UIBarBackground has been modified at this time
This is the end of the content of "what is the impact of the iOS navigation bar on the controller view". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.