UIViewController In-Call Status Bar Issue

前端 未结 8 999
误落风尘
误落风尘 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:29

    In my case, I'm using custom presentation style for my ViewController. The problem is that the Y position is not calculated well. Let's say the original screen height is 736p. Try printing the view.frame.origin.y and view.frame.height, you'll find that the height is 716p and the y is 20. But the display height is 736 - 20(in-call status bar extra height) - 20(y position). That is why our view is cut from the bottom of the ViewController and why there's a 20p margin to the top. But if you go back to see the navigation controller's frame value. You'll find that no matter the in-call status bar is showing or not, the y position is always 0.

    So, all we have to do is to set the y position to zero.

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    
        let f = self.view.frame
    
        if f.origin.y != 0 {
            self.view.frame = CGRect(x: f.origin.x, y: 0, width: f.width, height: f.height)
            self.view.layoutIfNeeded()
            self.view.updateConstraintsIfNeeded()
        }
    }
    

提交回复
热议问题