本文主要是介绍【iOS】状态栏颜色和pop手势,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
说明
- UINavigationController 管理状态栏颜色,需要转发给单个控制器
class NavController: UINavigationController {override func viewDidLoad() {super.viewDidLoad()}override var preferredStatusBarStyle: UIStatusBarStyle {let top = visibleViewControllerreturn top?.preferredStatusBarStyle ?? super.preferredStatusBarStyle}
}
隐藏导航栏手势问题
class ViewController: UIViewController, UIGestureRecognizerDelegate {var pp: Any?private lazy var button: UIButton = {let btn = UIButton()btn.backgroundColor = .redbtn.addTarget(self, action: #selector(test), for: .touchUpInside)return btn}()override func viewDidLoad() {super.viewDidLoad()view.backgroundColor = .whiteview.addSubview(button)button.frame = CGRect(x: 100, y: 200, width: 44, height: 44)self.navigationController?.setNavigationBarHidden(true, animated: false)let count = navigationController?.viewControllers.count ?? 0button.setTitle("\(count)", for: .normal)pp = navigationController?.interactivePopGestureRecognizer?.delegate}override func viewDidAppear(_ animated: Bool) {super.viewDidAppear(animated)let count = navigationController?.viewControllers.count ?? 0if count > 1 {print("self-delegate")navigationController?.interactivePopGestureRecognizer?.delegate = self} else {print("nil-delegate")navigationController?.interactivePopGestureRecognizer?.delegate = pp as? UIGestureRecognizerDelegate}}@objc func test() {let controller = ViewController()navigationController?.pushViewController(controller, animated: true)}override var prefersStatusBarHidden: Bool {return false}override var preferredStatusBarStyle: UIStatusBarStyle {print("\(#function)")guard let nav = navigationController else {print("1")return .default}if nav.viewControllers.count % 2 == 0 {print("2")return .darkContent}print("3")return .lightContent}
}
这篇关于【iOS】状态栏颜色和pop手势的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!