bryankeller / BLKFlexibleHeightBar

Create condensing header bars like those seen in the Facebook, Square Cash, and Safari iOS apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot reuse initialViewLayoutAttributes?

liuxuan30 opened this issue · comments

commented

I tried to reuse initialViewLayoutAttributes like below:
I have two subviews, and each time I just reuse the initial and final layout attributes. However at run time, I found the self.titleView's initial frame is already same as self.navigationCollectionView.

I had to create two copies for each view, and the titleView frame is correct then. Is this a bug?

    // configure layout attributes for titleView
    BLKFlexibleHeightBarSubviewLayoutAttributes *initialViewLayoutAttributes = [[BLKFlexibleHeightBarSubviewLayoutAttributes alloc] init];
    initialViewLayoutAttributes.frame = CGRectMake(0,0,self.view.bounds.size.width,64);
    BLKFlexibleHeightBarSubviewLayoutAttributes *finalViewLayoutAttributes = [[BLKFlexibleHeightBarSubviewLayoutAttributes alloc] initWithExistingLayoutAttributes:initialViewLayoutAttributes];
    finalViewLayoutAttributes.transform = CGAffineTransformMakeTranslation(0, -44);
    [self.titleView addLayoutAttributes:initialViewLayoutAttributes forProgress:0.0];
    [self.titleView addLayoutAttributes:finalViewLayoutAttributes forProgress:1.0];

    // configure layout attributes for navigationCollectionView
    initialViewLayoutAttributes.frame = CGRectMake(0,64,self.view.bounds.size.width,44);
    finalViewLayoutAttributes = [[BLKFlexibleHeightBarSubviewLayoutAttributes alloc] initWithExistingLayoutAttributes:initialViewLayoutAttributes];
    finalViewLayoutAttributes.transform = CGAffineTransformMakeTranslation(0, -44);
    [self.navigationCollectionView addLayoutAttributes:initialViewLayoutAttributes forProgress:0.0];
    [self.navigationCollectionView addLayoutAttributes:finalViewLayoutAttributes forProgress:1.0];

From what I've seen is the way the library works, is not a bug. It doesn't make a copy of the layout attributes everytime you add one to a view, so yes, you need to do a new one for each.

That's correct. Theres a convenience initializer for BLKFlexibleHeightBarSubviewLayoutAttributes To init a new set of layout attributes exactly like an existing one. See initWithExistingLayoutAttributes

commented

do you consider make it re-usable? kind of verbose when adding the attributes