How can I detect UIStatusBar hide and show?

后端 未结 4 1073
一个人的身影
一个人的身影 2021-01-18 12:00

I\'m trying to detect hidden and show of iPhone\'s UIStatusBar but failed. Are there any solution can help me, like KVO or something else?

4条回答
  •  不思量自难忘°
    2021-01-18 12:22

    From iOS 11 and up you can subclass the UIView of the view controller and override safeAreaInsetsDidChange:

    override func safeAreaInsetsDidChange() {
      super.safeAreaInsetsDidChange()
      // adapt your view
    }
    

    Your view must share the top rect with the status bar for this to work. (But if it doesn't, you probably wouldn't need to detect changes anyway).

提交回复
热议问题