Swift: How to refresh UICollectionView layout after rotation of the device

后端 未结 14 922
闹比i
闹比i 2020-12-01 02:38

I used UICollectionView (flowlayout) to build a simple layout. the width for each cell is set to the width of screen using self.view.frame.width

but whe

14条回答
  •  感情败类
    2020-12-01 03:13

    you can update your UICollectionView Layout by using

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        if isLandscape {
            return CGSizeMake(yourLandscapeWidth, yourLandscapeHeight)
        }
        else {
            return CGSizeMake(yourNonLandscapeWidth, yourNonLandscapeHeight)
        }
    }
    

提交回复
热议问题