Git Product home page Git Product logo

Comments (1)

liuxuan30 avatar liuxuan30 commented on September 20, 2024

Spend lots of time on it, and finally I write a custrom bahavior definer to do my job.

Some key notes are:

  1. make sure you set your scroll view's contentInset
  2. setup min height equals the pinned view height

Behaviour definer is just the same as the facebook style code. nothing more.

View controller demo code:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNeedsStatusBarAppearanceUpdate];
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) collectionViewLayout:[[UICollectionViewFlowLayout alloc] init]];
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    self.collectionView.dataSource = self;
    [self.view addSubview:self.collectionView];
    self.collectionView.backgroundColor = [UIColor blueColor];
    BLKFlexibleHeightBar *myBar = [[BLKFlexibleHeightBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 100)];
    myBar.minimumBarHeight = 40;
    myBar.backgroundColor = [UIColor redColor];
    [self.view addSubview:myBar];
    myBar.behaviorDefiner = [[MyBehaviorDefiner alloc] init];
    UIView *menu = [[UIView alloc] init];
    self.collectionView.delegate = myBar.behaviorDefiner;
    self.collectionView.contentInset = UIEdgeInsetsMake(myBar.maximumBarHeight, 0, 0, 0); // must have
    BLKFlexibleHeightBarSubviewLayoutAttributes *initialViewLayoutAttributes = [[BLKFlexibleHeightBarSubviewLayoutAttributes alloc] init];
    initialViewLayoutAttributes.frame = CGRectMake(0,60,self.view.bounds.size.width,40);
    [menu addLayoutAttributes:initialViewLayoutAttributes forProgress:0];
    BLKFlexibleHeightBarSubviewLayoutAttributes *finalViewLayoutAttributes = [[BLKFlexibleHeightBarSubviewLayoutAttributes alloc] initWithExistingLayoutAttributes:initialViewLayoutAttributes];
    finalViewLayoutAttributes.transform = CGAffineTransformMakeTranslation(0, -40);
    [menu addLayoutAttributes:finalViewLayoutAttributes forProgress:1.0];
    menu.backgroundColor = [UIColor yellowColor];
    [myBar addSubview:menu];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 20;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor greenColor];
    return cell;
}

from blkflexibleheightbar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.