没有缺口状态栏的设备上的动画不会以交互式弹出手势进行动画处理

时间:2019-05-24 06:44:54

标签: swift uiviewcontroller uinavigationcontroller

我有两个视图控制器,第一个隐藏了状态和导航栏,第二个显示了状态和导航栏, 使用iPhone X,Xs,Xs Max时。弹出式互动手势效果不错 但是当使用不带缺口弹出式互动手势的设备时,请勿为隐藏状态栏设置动画

class ViewController1: UIViewController {

    override var prefersStatusBarHidden: Bool{
        return true
    }

    override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation{
        return .slide
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        navigationController?.setNavigationBarHidden(true, animated: true)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .red

        navigationController?.isNavigationBarHidden = true

        addBtn()
    }

    // add button in center view
    fileprivate func addBtn() {
        let button = UIButton()
        view.addSubview(button)
        button.translatesAutoresizingMaskIntoConstraints = false
        button.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        button.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        button.setTitle("go to 2 vc", for: .normal)
        button.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(goTo2)))
    }


    @objc func goTo2(){
        navigationController?.pushViewController(ViewController2(), animated: true)
    }
}


class ViewController2: UIViewController {

    override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation{
        return .slide
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .blue

        navigationController?.setNavigationBarHidden(false, animated: true)
    }
}

0 个答案:

没有答案