How to ignore the safe area when using keyboardLayoutGuide

I have a full screen list and want to use the new keyboardLayoutGuide constraint, but by default it uses the safe area inset. How can I disable this so my list goes all the way to the bottom of the screen when the keyboard is not shown?

NSLayoutConstraint.activate([
   collectionView.topAnchor.constraint(equalTo: view.topAnchor),
   collectionView.bottomAnchor.constraint(equalTo: view.keyboardLayoutGuide.topAnchor),
   collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
   collectionView.trailingAnchor.constraint(equalTo:  view.trailingAnchor)
])

Answered by rspoon3 in 763210022

usesBottomSafeArea is a new property introduced in iOS 17 to address this. Watch Keep up with the keyboard for more info.

view.keyboardLayoutGuide.usesBottomSafeArea = false
        
NSLayoutConstraint.activate([
   collectionView.topAnchor.constraint(equalTo: view.topAnchor),
   collectionView.bottomAnchor.constraint(equalTo: view.keyboardLayoutGuide.topAnchor),
   collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
   collectionView.trailingAnchor.constraint(equalTo:  view.trailingAnchor)
])

I've got the same problem. Is there still no solution to this yet? This is a very common use case, and any time someone wants to use keyboardLayoutGuide with a scroll view, it no longer becomes feasible.

Indeed it's very annoying. Trying to solve this same issue for a few days already. Apparently the only solution is fall back to the old approach reacting on keyboard related notifications etc.

Accepted Answer

usesBottomSafeArea is a new property introduced in iOS 17 to address this. Watch Keep up with the keyboard for more info.

view.keyboardLayoutGuide.usesBottomSafeArea = false
        
NSLayoutConstraint.activate([
   collectionView.topAnchor.constraint(equalTo: view.topAnchor),
   collectionView.bottomAnchor.constraint(equalTo: view.keyboardLayoutGuide.topAnchor),
   collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
   collectionView.trailingAnchor.constraint(equalTo:  view.trailingAnchor)
])
How to ignore the safe area when using keyboardLayoutGuide
 
 
Q