UICollectionView in landscape on iPhone X

前端 未结 6 773
余生分开走
余生分开走 2021-01-31 02:41

When iPhone X is used landscape, you\'re supposed to check safeAreaInsets to make suitably large gutters on the left and right. UITableView has the new insetsContentViewsT

6条回答
  •  南旧
    南旧 (楼主)
    2021-01-31 02:59

    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.

提交回复
热议问题