1.狀態(tài)欄
-
控制狀態(tài)欄的對象
UIApplicationUINavigationControllerUIViewController
-
控制區(qū)分
-
View controller-based status bar appearance設(shè)置為false,由UIApplication控制狀態(tài)欄。iOS 9以后被棄用,可以使用,會爆警告??。
///隱藏 與顯示 UIApplication.shared.setStatusBarHidden(true, with:UIStatusBarAnimation.none) UIApplication.shared. isStatusBarHidden = true /// 樣式 UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.default, animated: true) UIApplication.shared.statusBarStyle = .defaul UIApplication.shared.statusBarStyle = .default /// 方向 UIApplication.shared.setStatusBarOrientation(UIInterfaceOrientation.portrait, animated: true) UIApplication.shared.statusBarOrientation = UIInterfaceOrientation.portrait-
View controller-based status bar appearance設(shè)置為true。狀態(tài)欄由ViewController控制。
/// 隱藏 override var prefersStatusBarHidden: Bool{ return true } ///樣式 override var preferredStatusBarStyle: UIStatusBarStyle{ return .default } /// 動畫方式 override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation{ return UIStatusBarAnimation.none } /// 如果ViewController 包含一個子控制,想由子控制器控制狀態(tài)欄。 override var childForStatusBarStyle: UIViewController?{ return childVC // 默認(rèn)為nil self控制 } override var childForStatusBarHidden: UIViewController?{ return childVC // 默認(rèn)為nil self控制 } /// 如果是Modal Presentation 呈現(xiàn)的視圖, 若視圖fullscreen 全屏,則由改視圖控制.否則由其下層視圖控制。 ///若在視圖non-fullscreen非全屏是強行控制,則重寫下面屬性,返回true. /// 父類定義的屬性讀寫 實現(xiàn)其set get override var modalPresentationStyle: UIModalPresentationStyle{ get{ return .formSheet } set{ super.modalPresentationStyle = newValue } } override var modalPresentationCapturesStatusBarAppearance: Bool{ return true }- 如果有導(dǎo)航欄控制器。相當(dāng)于導(dǎo)航欄控制器內(nèi)添加子控制器,等同于控制器內(nèi)添加子控制器的處理方法
- 導(dǎo)航欄控制狀態(tài)欄。
/// 隱藏 override var prefersStatusBarHidden: Bool{ return true } ///樣式 override var preferredStatusBarStyle: UIStatusBarStyle{ return .default } /// 動畫方式 override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation{ return UIStatusBarAnimation.none }-
ViewController控制狀態(tài)欄 。
override var childForStatusBarStyle: UIViewController?{ return visibleViewController // 導(dǎo)航欄棧內(nèi)最頂部可見控制器 } override var childForStatusBarHidden: UIViewController?{ return visibleViewController }
-
- 導(dǎo)航欄
navigationController?.setNavigationBarHidden(true, animated: animated)
/// 直接隱藏navigationBar視圖,不接收事件,仍保留在父視圖的subviews內(nèi),仍然參與視圖布局。
/// 此方法隱藏顯示視圖 可能會導(dǎo)致一些問題 。
///如B界面同時隱藏狀態(tài)欄和導(dǎo)航欄,A界面不隱藏,當(dāng)從B返回A界面時 A界面的導(dǎo)航欄上移到狀態(tài)欄的位置。上面的方法不會出現(xiàn)該問題
navigationController?.navigationBar.isHidden = true
3.標(biāo)簽欄
/// 可以在展示的界面的任何位置設(shè)置隱藏標(biāo)簽欄,但返回時上個界面的額標(biāo)簽欄會出現(xiàn)
tabBarController?.tabBar.isHidden = true
/// 在push 時獲得控制器設(shè)置 隱藏標(biāo)簽欄,覆蓋下一級
vc.hidesBottomBarWhenPushed = true
/// 可以在UINavigationController 內(nèi)統(tǒng)一設(shè)置
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
if viewControllers.count == 1 { /// rootViewController 的下一個控制器設(shè)置隱藏
viewController.hidesBottomBarWhenPushed = true
}
super.pushViewController(viewController, animated: animated)
}
///上面方法可能會導(dǎo)致 tabbar 的title選中字體顏色 或 圖片 渲染 問題 可能變成藍(lán)色
要在 UITabBarController 的初始化時 設(shè)置 渲染顏色 tintColor
tabBar.tintColor = KDEColorRBG