Having the same issue. This worked for me:
override func viewDidLoad() {
if #available(iOS 11.0, *) {
collectionView?.contentInsetAdjustmentBehavior = .always
}
}
The documentation for the .always
enum case says:
Always include the safe area insets in the content adjustment.
This solution works correctly also in the case the phone is rotated.