UIViewController In-Call Status Bar Issue

前端 未结 8 951
误落风尘
误落风尘 2020-12-01 12:24

Issue:

Modally presented view controller does not move back up after in-call status bar disappears, leaving 20px empty/transparent space at the top.<

8条回答
  •  眼角桃花
    2020-12-01 13:20

    I think this is a bug in UIKit. The containerView that contains a presented controller's view which was presented using a custom transition does not seem to move back completely when the status bar returns to normal size. (You can check the view hierarchy after closing the in call status bar)

    To solve it you can provide a custom presentation controller when presenting. And then if you don't need the presenting controller's view to remain in the view hierarchy, you can just return true for shouldRemovePresentersView property of the presentation controller, and that's it.

    func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
        return PresentationController(presentedViewController: presented, presenting: presenting)
    }
    
    class PresentationController: UIPresentationController {
        override var shouldRemovePresentersView: Bool {
            return true
        }
    }
    

    or if you need the presenting controller's view to remain, you can observe status bar frame change and manually adjust containerView to be the same size as its superview

    class PresentationController: UIPresentationController {
        override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) {
            super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
            NotificationCenter.default.addObserver(self,
                                                   selector: #selector(self.onStatusBarChanged),
                                                   name: .UIApplicationWillChangeStatusBarFrame,
                                                   object: nil)
        }
    
        @objc func onStatusBarChanged(note: NSNotification) {
            //I can't find a way to ask the system for the values of these constants, maybe you can
            if UIApplication.shared.statusBarFrame.height <= 20,
                let superView = containerView?.superview {
                UIView.animate(withDuration: 0.4, animations: {
                    self.containerView?.frame = superView.bounds
                })
            }
        }
    }
    

提交回复
热议问题