bryankeller / BLKFlexibleHeightBar

Create condensing header bars like those seen in the Facebook, Square Cash, and Safari iOS apps.
MIT License
3.04k stars 338 forks source link

Cannot reuse initialViewLayoutAttributes? #26

Open liuxuan30 opened 9 years ago

liuxuan30 commented 9 years ago

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];
palcalde commented 9 years ago

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.

bryankeller commented 9 years ago

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

liuxuan30 commented 9 years ago

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