Implementing layoutAttributesForItem(at:)

Another way a collection view can request layout attributes for its layout is by requesting the attributes for a single item. Because the collection view does so by supplying an index path, this method is quite simple to implement. The layout you implemented assumes that only a single section exists in the collection view and the layout attributes array is sorted by index path because that's the order in which all items were inserted into the array. This means that you can use the supplied index path's row to fetch the correct layout attributes from the layout attributes array:

override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
  return layoutAttributes[indexPath.row]
}

The last remaining method to implement is shouldInvalidateLayout(forBoundsChange:).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset