-1

What is the difference between:

self.collectionView.contentSize.height and self.collectionView.bounds.origin.y?

The latter always seems to be smaller than the former?

Any clarifying sketches would be highly appreciated.

MJQZ1347
  • 2,607
  • 7
  • 27
  • 49

2 Answers2

0

contentSize is the size of the content, which is shown by scrolling. say you have 10 cell's sizing of 3600x1200. Then the content size will be 3600x1200. Bound will be the actual frame of the collectionview.

For more information

  1. contentSize is not direct property of UICollectionView. It's derived from the UIScrollView. check here

happy coding.

Ratul Sharker
  • 7,484
  • 4
  • 35
  • 44
  • How can the frame (bounds) be smaller than the content size itself? – MJQZ1347 Jun 18 '16 at 13:52
  • As `UICollectionView` is not showing all the content at a time, it's just windowing some content, so in this case, content size must be greater than the frame size. – Ratul Sharker Jun 18 '16 at 13:55
  • But `self.collectionView.bounds.origin.y` is often greater than `UIScreen.mainScreen().bounds.height`. So it is actually not the frame for the **visible** area? Any sketches would be highly appreciated. – MJQZ1347 Jun 18 '16 at 13:57
  • In case, let you have only 2 cells overall, in that case say the size is 100x200 and your collectionView's frame size covering the whole viewController. In this particular cases, collectionView frame will be greater than the content size. In this case, no scroll can be done, because there is nothing left to show, Everything is shown. – Ratul Sharker Jun 18 '16 at 13:58
  • `bounds` actually derived from `UIView`. I fear it is actually the visible area. check [here](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/index.html#//apple_ref/occ/instp/UIView/bounds) – Ratul Sharker Jun 18 '16 at 14:03
0

The value of self.collectionView.bounds.origin.y is 0. Because the bounds of an UIView is the rectangle which is expressed by its own co-ordinate system. Refer to Cocoa: What's the difference between the frame and the bounds?

self.collectionView.contentSize.height = contentSize of scrollview

Let you have a collection view(scroll vertically) whose frame is (0,64,320,504) and size of its each cell is (100,100) and you have 20 item. So, each row of collection view contain 3 cell. Now, to fit 20 item in collectionview 7 row will generate and we can see all those item by scrolling vertically.

Actual size of collectionview is (320,504) and the contentsize is (320,700).

Note:Assuming collectionview is scrolls vertically and there is no space between two row.

Community
  • 1
  • 1
Gour
  • 50
  • 8