gskbyte / GSKStretchyHeaderView

A generic stretchy header for UITableView and UICollectionView
MIT License
1.75k stars 187 forks source link

Bad Calculation for UICollectionView #41

Closed glassipbel closed 7 years ago

glassipbel commented 7 years ago

There is a bug when you use this library for a collectionView: Steps for replicate the bug:

  1. Create a collection view.
  2. Set the property: sectionHeadersPinToVisibleBounds = YES. (for the UICollectionViewFlowLayout)
  3. Add a header for any section.
  4. Configure the strechy subclass like this: header.minimumContentHeight = 64 header.maximumContentHeight = 200 header.expansionMode = GSKStretchyHeaderViewExpansionMode.topOnly header.contentShrinks = true header.contentExpands = true header.contentAnchor = GSKStretchyHeaderViewContentAnchor.top
  5. Run the app and you will see that the section header pins to the maximumContentHeight but the sticky header could be minimized at that moment. So that's the issue.

Attach you will find an screenshot. (PS: The header is located in section 1, not in section 0, so this collection view has: 3 rows in section 0 1 header in section 1 5 rows in section 1) img_3622

gskbyte commented 7 years ago

Hey, that's one interesting problem. Before sectionHeadersPinToVisibleBounds was introduced, I discovered the same problem but for UITableView. I propose a solution in the example GSKVisibleSectionHeadersViewController. Try to have a look at that and see if you can replicate it, if not, I will give it a try this week.

Thanks for reporting the issue, let me know about your progress!

glassipbel commented 7 years ago

Thanks :P The problem is now solved.

glassipbel commented 7 years ago

Actually i can apply the same solution as the tableview that you suggested, but i believe it could be cleaner. This library is really awesome and i believe that if you could make that fix to work properly without this tweak the library would look even cleaner.

gskbyte commented 7 years ago

Well, if you could give me a hint about this solution I would be more than glad to apply it, but honestly I don't know right now how to improve it without massive changes to the library.

AlexKel commented 6 years ago

@kbelter How did you managed to fix this in UICollectionView? I've got it working half way, but I cannot figure out how to substitute the tableHeaderView proposed in the solution. I'm currently experiencing same issue if you'd remove tableHeaderView code from the example. Section header is appearing behind (and up) sketchy header.

glassipbel commented 6 years ago

@AlexKel Hi! I manage to solve the issue by:

  1. Configuring the stretchy view like this: header.minimumContentHeight = 64 header.maximumContentHeight = 264 header.expansionMode = GSKStretchyHeaderViewExpansionMode.topOnly header.contentShrinks = true header.contentExpands = true header.contentAnchor = GSKStretchyHeaderViewContentAnchor.bottom header.manageScrollViewInsets = false

  2. Adding in the section 0 a UICollectionReusableView (it doesn't matter the content you wont see it) and the height of this header should be CGSize(width: UIScreen.main.bounds.width, height: header.maximumContentHeight - header.minimumContentHeight)

  3. Finally when you add the stretchy header to your collectionview add this line after that: collectionView.addSubview(strechyHeader) collectionView.contentInset.top = strechyHeader.minimumContentHeight

That's it :P

gskbyte commented 6 years ago

Thanks guys, you're amazing 💯

AlexKel commented 6 years ago

Thanks @kbelter ! Unfortunately this didn't help me.. I needed the very 1st section header to be visible :) I didn't manage to resolve the issue, but changed my structure to have this small section header view as a subview of a stretchy header. I only have 1 section in my collection view, so this works as expected :)