Why is UICollectionView insetForSectionsAtIndex not called?

I want to use the following function, but unfortunately they do not call it.

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewFlowLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
        let cellCount = Double(collectionView.numberOfItems(inSection: section))
        if let cell = collectionView.cellForItem(at: IndexPath(row: 0, section: section))
        {
            let cellWidth = Double(cell.frame.size.width)
            let totalCellWidth = cellWidth * cellCount
            let cellSpacing = Double(collectionViewLayout.minimumInteritemSpacing)
            let totalSpacingWidth = cellSpacing * (cellCount - 1)

            let leftInset = (collectionView.frame.width - CGFloat(totalCellWidth + totalSpacingWidth)) / 2
            let rightInset = leftInset

            return UIEdgeInsetsMake(0, leftInset, 0, rightInset)
        }

    return collectionView.layoutMargins
}

I get the following console errors, but my cell is smaller than my View collection, and I set the section inserts and layout fields to 0.

2017-03-30 11: 25: 14.624 Prep [92400: 1862856] UICollectionViewFlowLayout , : 2017-03-30 11: 25: 14.624 Prep [92400: 1862856] UICollectionView , . 2017-03-30 11: 25: 14.624 Prep [92400: 1862856] UICollectionViewFlowLayout, ; layer =; contentOffset: {0, 0}; contentSize: {0, 68.5} > :. 2017-03-30 11: 25: 14.625 Prep [92400: 1862856] UICollectionViewFlowLayoutBreakForInvalidSizes, .   → 42.0

enter image description here

class OverviewViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet weak var vipCollectionView: UICollectionView!

var hostedMeetingsArray: [String]?
var vipArray: [Attendee]?

class OverviewViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet weak var vipCollectionView: UICollectionView!

var hostedMeetingsArray: [String]?
var vipArray: [Attendee]?

enter image description here

+4
1

, , insetForSectionAt , , :

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {

   //access to minimumInteritemSpacing by casting to UICollectionViewFlowLayout
   let layout = collectionViewLayout as! UICollectionViewFlowLayout
   let spacing = layout.minimumInteritemSpacing       

   return UIEdgeInsetsMake(0.5,0,0.5,0)

}

UICollectionViewDelegateFlowLayout. insectionAt :

@available(iOS 6.0, *)
optional public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets

.

+1

Source: https://habr.com/ru/post/1673586/


All Articles