The height drawn in safeAreaInsets.bottom and Toolbar is different on iPad with SafeArea.

On an iPad with SafeArea, the height drawn in safeAreaInsets.bottom and Toolbar are different, so there is a gap between the Toolbar and the bottom.

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationController?.setToolbarHidden(false, animated: false)
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        let insetsBottom = self.view.safeAreaInsets.bottom
        let screenHeight = UIApplication.shared.keyWindow?.bounds.size.height ?? 0
        let toolbarFrameY = (self.navigationController?.toolbar.frame.origin.y ?? 0)
  
        print("safeAreaInsets.bottom=\(insetsBottom), toolbar.height with safeArea=\(screenHeight - toolbarFrameY)")
    }
}

But, When "Shows Toolbar" is checked in Storyboard, safeAreaInsets.bottom and the height drawn on the Toolbar match.

  • Why is the behavior different?
  • Is there any way to deal with this in code?

Version/Build

  • iOS15
  • Xcode 13.1
  • iPad mini 6th
The height drawn in safeAreaInsets.bottom and Toolbar is different on iPad with SafeArea.
 
 
Q