keighl / KTCenterFlowLayout

Aligns collection view cells to the center of the screen.
MIT License
455 stars 58 forks source link

when headerAttrs.frame.size is zero,it will be add to updatedAttributes and lead to a crash in IGListKit #26

Closed sunbohong closed 8 years ago

sunbohong commented 8 years ago

thanks for your contributation i want use KTCenterFlowLayout in IGListKit. but now,it will lead to a crash.

sunbohong commented 8 years ago

you can see this bug in https://github.com/sunbohong/IGListKit/commit/58536780d493690e1d7551912abf4114c122c0d0

and https://github.com/sunbohong/IGListKit/commit/12736c2cb083a6e0527076885a23ab02bc880495 fix this bug

keighl commented 8 years ago

Hey @sunbohong, thanks for the report and the pull! This sounds like an IGListKit bug, though. A frame with CGSizeZero is perfectly valid to the collection view. Have a closer look at what causes IGListKit to crash... (perhaps a division by zero? 😉 )

sunbohong commented 8 years ago

Hey @keighl , I use KTCenterFlowLayout in my project,but i don't have any headerview or footerview.

But now, KTCenterFlowLayout is different with UICollectionViewFlowLayout. It has more UICollectionViewLayoutAttributes for header and footer views.

(lldb) po [super layoutAttributesForElementsInRect:rect]
<__NSArrayM 0x6000000568f0>(
<UICollectionViewLayoutAttributes: 0x6000001f4100> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); frame = (0 0; 320 55); ,
<UICollectionViewLayoutAttributes: 0x6000001f3b00> index path: (<NSIndexPath: 0xc000000000000116> {length = 2, path = 1 - 0}); frame = (0 55; 320 55); ,
<UICollectionViewLayoutAttributes: 0x6000001f4400> index path: (<NSIndexPath: 0xc000000000000216> {length = 2, path = 2 - 0}); frame = (0 110; 320 55); ,
<UICollectionViewLayoutAttributes: 0x6000001f2900> index path: (<NSIndexPath: 0xc000000000000316> {length = 2, path = 3 - 0}); frame = (0 165; 320 55); ,
<UICollectionViewLayoutAttributes: 0x6000001f3800> index path: (<NSIndexPath: 0xc000000000000416> {length = 2, path = 4 - 0}); frame = (0 220; 320 55); ,
<UICollectionViewLayoutAttributes: 0x6000001f3100> index path: (<NSIndexPath: 0xc000000000000516> {length = 2, path = 5 - 0}); frame = (0 275; 320 55); 
)

(lldb) po [self layoutAttributesForElementsInRect:rect]
<__NSArrayM 0x608000054970>(
<UICollectionViewLayoutAttributes: 0x6080001f3400> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); frame = (0 0; 320 55); ,
<UICollectionViewLayoutAttributes: 0x6000001f3700> index path: (<NSIndexPath: 0xc000000000000116> {length = 2, path = 1 - 0}); frame = (0 55; 320 55); ,
<UICollectionViewLayoutAttributes: 0x6000001f4600> index path: (<NSIndexPath: 0xc000000000000116> {length = 2, path = 1 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (0 55; 0 0); zIndex = 10; ,
<UICollectionViewLayoutAttributes: 0x6000001f3e00> index path: (<NSIndexPath: 0xc000000000000116> {length = 2, path = 1 - 0}); element kind: (UICollectionElementKindSectionFooter); frame = (0 55; 0 0); zIndex = 10; ,
<UICollectionViewLayoutAttributes: 0x6000001f3200> index path: (<NSIndexPath: 0xc000000000000216> {length = 2, path = 2 - 0}); frame = (0 110; 320 55); ,
<UICollectionViewLayoutAttributes: 0x6000001f3600> index path: (<NSIndexPath: 0xc000000000000216> {length = 2, path = 2 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (0 110; 0 0); zIndex = 10; ,
<UICollectionViewLayoutAttributes: 0x6000001f3400> index path: (<NSIndexPath: 0xc000000000000216> {length = 2, path = 2 - 0}); element kind: (UICollectionElementKindSectionFooter); frame = (0 110; 0 0); zIndex = 10; ,
<UICollectionViewLayoutAttributes: 0x6000001f2b00> index path: (<NSIndexPath: 0xc000000000000316> {length = 2, path = 3 - 0}); frame = (0 165; 320 55); ,
<UICollectionViewLayoutAttributes: 0x6000001f3d00> index path: (<NSIndexPath: 0xc000000000000316> {length = 2, path = 3 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (0 165; 0 0); zIndex = 10; ,
<UICollectionViewLayoutAttributes: 0x6000001f3000> index path: (<NSIndexPath: 0xc000000000000316> {length = 2, path = 3 - 0}); element kind: (UICollectionElementKindSectionFooter); frame = (0 165; 0 0); zIndex = 10; ,
<UICollectionViewLayoutAttributes: 0x6000001f2c00> index path: (<NSIndexPath: 0xc000000000000416> {length = 2, path = 4 - 0}); frame = (0 220; 320 55); ,
<UICollectionViewLayoutAttributes: 0x6000001f2d00> index path: (<NSIndexPath: 0xc000000000000416> {length = 2, path = 4 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (0 220; 0 0); zIndex = 10; ,
<UICollectionViewLayoutAttributes: 0x6000001f2300> index path: (<NSIndexPath: 0xc000000000000416> {length = 2, path = 4 - 0}); element kind: (UICollectionElementKindSectionFooter); frame = (0 220; 0 0); zIndex = 10; ,
<UICollectionViewLayoutAttributes: 0x6000001f3300> index path: (<NSIndexPath: 0xc000000000000516> {length = 2, path = 5 - 0}); frame = (0 275; 320 55); ,
<UICollectionViewLayoutAttributes: 0x6000001f4300> index path: (<NSIndexPath: 0xc000000000000516> {length = 2, path = 5 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (0 275; 0 0); zIndex = 10; ,
<UICollectionViewLayoutAttributes: 0x6000001f3900> index path: (<NSIndexPath: 0xc000000000000516> {length = 2, path = 5 - 0}); element kind: (UICollectionElementKindSectionFooter); frame = (0 275; 0 0); zIndex = 10; 
)

(lldb)