UICollectionView in landscape on iPhone X

前端 未结 6 754
余生分开走
余生分开走 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 03:08

    If you're adding collection view as your main view's subview programmatically - then you can just do this in your viewDidLoad method:

    collectionView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(collectionView)
    
    NSLayoutConstraint.activate([
            collectionView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
            collectionView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
            collectionView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
            collectionView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor)
    ])
    

提交回复
热议问题