Why does UICollectionView log an error when the cells are fullscreen?

后端 未结 10 1247
悲&欢浪女
悲&欢浪女 2020-12-08 04:06

I have a UICollectionViewController using a UICollectionViewFlowLayout where my itemSize is the size of the UICollectionView

相关标签:
10条回答
  • 2020-12-08 04:50

    In my case I have to reduce bottom inset (from 20 to 0) of cell as I have reduced 20 from height of collectionview From

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
    -        return UIEdgeInsets(top: 10, left: 10, bottom: 20, right: 10)
    +        return UIEdgeInsets(top: 10, left: 10, bottom: 0, right: 10)
         }
    
    func collectionView(_ collectionView: UICollectionView,
                            layout collectionViewLayout: UICollectionViewLayout,
                            sizeForItemAt indexPath: IndexPath) -> CGSize {
            let size = CGSize(width: 350, height: collectionView.bounds.size.height - 20)
            return size
        }
    
    0 讨论(0)
  • 2020-12-08 05:03

    This way had worked for me perfectly!.

    I just subtracted the top and bottom insets from the view's height as said in that error.

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: view.frame.width , height: view.frame.height - (view.safeAreaInsets.top + view.safeAreaInsets.bottom))
    }
    

    I hope it helps!

    0 讨论(0)
  • 2020-12-08 05:04

    iOS 11 update: automaticallyAdjustsScrollViewInsets is deprecated in iOS 11.0.

    Apple recommends using UIScrollView's contentInsetAdjustmentBehavior method instead. I set this value to .never and the error has gone. You can also set this property in Interface Builder.

    0 讨论(0)
  • ios 10: topmost view was not connected to the view outlet

    0 讨论(0)
提交回复
热议问题