UICollectionView - resizing cells on device rotate - Swift

后端 未结 9 1601
醉梦人生
醉梦人生 2020-12-04 23:12

I\'ve created a UICollectionView, so that I can arrange views into neat columns. I\'d like there to be a single column on devices > 500 pixels wide.

In order to achi

9条回答
  •  广开言路
    2020-12-04 23:50

    Perhaps the most straight way to make this is to invalidateLayout during the viewWillTransitionToSize:

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        guard let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout else {
            return
        }
        flowLayout.invalidateLayout()
    }
    

提交回复
热议问题