chiahsien/CHTCollectionViewWaterfallLayout

does not work when auto layout turn on

edwardyue opened this issue · 8 comments

Hi team,

The cell looks weird after turn on the Autolayout. I am using objective -C one. Could you help?

thanks!

Show us the code.

Please find below. The code is simple.

In viewdidload:

CHTCollectionViewWaterfallLayout *layout = [[

CHTCollectionViewWaterfallLayout alloc] init];

layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);

layout.headerHeight = 15;

layout.footerHeight = 10;

layout.minimumColumnSpacing = 5;

layout.minimumInteritemSpacing = 5;



[self.imagesCollection setCollectionViewLayout:layout];



 _imagesCollection.autoresizingMask = UIViewAutoresizingFlexibleHeight

| UIViewAutoresizingFlexibleWidth;

_imagesCollection.dataSource = self;

_imagesCollection.delegate = self;

_imagesCollection.backgroundColor = [UIColor whiteColor];

Other code copy from your example.

#pragma mark - CHTCollectionViewDelegateWaterfallLayout

  • (NSArray *)cellSizes {

    if (!_cellSizes) {

    _cellSizes = @[
    
                   [NSValue valueWithCGSize:CGSizeMake(400, 550)],
    
                   [NSValue valueWithCGSize:CGSizeMake(1000, 665)],
    
                   [NSValue valueWithCGSize:CGSizeMake(1024, 689)],
    
                   [NSValue valueWithCGSize:CGSizeMake(640, 427)]
    
                   ];
    

    }

    return _cellSizes;

}

  • (CGSize)collectionView:(UICollectionView *)collectionView layout:(
    UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(
    NSIndexPath *)indexPath {

    return [self.cellSizes[indexPath.item % 4] CGSizeValue];

}

@EnD

Nelson notifications@github.com 於 2016年6月24日 星期五寫道:

Show us the code.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#139 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AQhBU92Pcs-Ht-AsXgJ0Lhrwwy-f6BYuks5qO3RYgaJpZM4I9dvY
.

It seems that you doesn't turn on autolayout.

Anyway, try to setup collection view layout in

- (void)viewDidLayoutSubviews {
}

Thanks Nelson,

i turn on the autolayout through Xcode by clicking the Use autolayout
checkbox in the main storyboard.

Anyway, i will try your suggestion.

Thanks and Regards.
edward

On Fri, Jun 24, 2016 at 2:20 PM, Nelson notifications@github.com wrote:

It seems that you doesn't turn on autolayout.

Anyway, try to setup collection view layout in

  • (void)viewDidLayoutSubviews {
    }


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#139 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AQhBU_KrlaxYV5Oe2k9uYdRq2WTXt1qOks5qO3cUgaJpZM4I9dvY
.

Thanks and Regards,
Edward Chan Woon Yue

Hi Nelson,

Sorry that I got follow error when move the code to viewDidlayoutsubviews

-(void)viewDidLayoutSubviews

{

CHTCollectionViewWaterfallLayout *layout = [[

CHTCollectionViewWaterfallLayout alloc] init];

layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);

layout.headerHeight = 15;

layout.footerHeight = 10;

layout.minimumColumnSpacing = 5;

layout.minimumInteritemSpacing = 5;



[_imagesCollection setCollectionViewLayout:layout];

}

2016-06-24 22:35:06.825 speeddate[1015:363452] ** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '***
setObjectForKey: object cannot be nil (key: <NSIndexPath:
0xc000000000000016> {length = 2, path = 0 - 0})'*

*** First throw call stack:

(0x183b52db0 0x1831b7f80 0x183a38494 0x1894f7560 0x183a38cac 0x183a38b84
0x1894f7254 0x1894f7690 0x183a38cac 0x183a38b60 0x188e416c8 0x188e40870
0x100120a40 0x188cac224 0x18663e994 0x1866395d0 0x188cc30a4 0x188d71694
0x188d6f06c 0x188d87dd8 0x188d87ac4 0x188d877cc 0x188cebc28 0x188ce9ea4
0x188d7b234 0x188d70d48 0x188d6fef4 0x188d6fb1c 0x188d6fa84 0x188cac1e4
0x18663e994 0x1866395d0 0x186639490 0x186638ac0 0x186638820 0x188ca25f8
0x183b08728 0x183b064cc 0x183b068fc 0x183a30c50 0x185318088 0x188d1a088
0x100132474 0x1835ce8b8)

libc++abi.dylib: terminating with uncaught exception of type NSException

On Fri, Jun 24, 2016 at 5:47 PM, Edward Chan yue.edward@gmail.com wrote:

Thanks Nelson,

i turn on the autolayout through Xcode by clicking the Use autolayout
checkbox in the main storyboard.

Anyway, i will try your suggestion.

Thanks and Regards.
edward

On Fri, Jun 24, 2016 at 2:20 PM, Nelson notifications@github.com wrote:

It seems that you doesn't turn on autolayout.

Anyway, try to setup collection view layout in

  • (void)viewDidLayoutSubviews {
    }


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#139 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AQhBU_KrlaxYV5Oe2k9uYdRq2WTXt1qOks5qO3cUgaJpZM4I9dvY
.

Thanks and Regards,
Edward Chan Woon Yue

Thanks and Regards,
Edward Chan Woon Yue

Show me your sample project.

Hi Nelson,

unfortunately, it is not easy for me to build a sample project.

That said, i know the issue now. The cell looks good when I set background
color as black. However just picture i assigned cannot fully fit in to the
cell. It was fix perfectly before autolayout turn on.

Any idea?

Thanks
Edward

On Sat, Jun 25, 2016 at 1:11 AM, Nelson notifications@github.com wrote:

Show me your sample project.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#139 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AQhBU35BxJZrrsOoyOmwt9F0mAD97Q8Qks5qPA--gaJpZM4I9dvY
.

Thanks and Regards,
Edward Chan Woon Yue

Please ignore. I fixed the issue. Many thanks

Edward Chan yue.edward@gmail.com 於 2016年6月25日星期六 寫道:

Hi Nelson,

unfortunately, it is not easy for me to build a sample project.

That said, i know the issue now. The cell looks good when I set background
color as black. However just picture i assigned cannot fully fit in to the
cell. It was fix perfectly before autolayout turn on.

Any idea?

Thanks
Edward

On Sat, Jun 25, 2016 at 1:11 AM, Nelson <notifications@github.com
javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:

Show me your sample project.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#139 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AQhBU35BxJZrrsOoyOmwt9F0mAD97Q8Qks5qPA--gaJpZM4I9dvY
.

Thanks and Regards,
Edward Chan Woon Yue

Thanks and Regards,
Edward Chan Woon Yue