A Swift project explaining how to animate a header above a UITableView
Checkout my blog post here for details on how this project works!
A Swift project explaining how to animate a header above a UITableView
A Swift project explaining how to animate a header above a UITableView
Checkout my blog post here for details on how this project works!
Thanks so much for this code and blog post; so useful!
I noticed an odd behavior where when I'd scroll up from the bottom, the header would be late to un-collapse... I'd have to get a couple cells up from the bottom before it started to un-collapse.
In my case I'm using this technique on a collection view appearing inside a UITabBarController, where the collection view scrolls under the bottom bar.
It occurred to me the amount I was needing to scroll up before triggering the uncollapse was roughly the height of the bottom bar. I realized that the calculation of absoluteBottom
probably needs to take this extra space into account.
After accounting for the layout margins (and content inset, same issue) in the absoluteBottom
calculation, the un-collapse is now pixel-perfect!
I'll have a PR for you in a second to account for it on this project too. But I wanted to document this in an issue in case someone else was running into the same problem.
When i scroll down, isScrollingDown derives as false and if i scroll up then isScrollingUp is false.
why this opposite calculation?
I have UISearchBar in place UIView.
when i scroll up, scrollView.contentOffset.y
gives positive value. Should it not give negative?
Thanks
Ashish
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let scrollDiff = scrollView.contentOffset.y - self.previousScrollOffset
let absoluteTop: CGFloat = 0;
let absoluteBottom: CGFloat = scrollView.contentSize.height - scrollView.frame.size.height;
let isScrollingDown = scrollDiff > 0 && scrollView.contentOffset.y > absoluteTop
let isScrollingUp = scrollDiff < 0 && scrollView.contentOffset.y < absoluteBottom
var newHeight = self.searchBarHeightConstraint.constant
if isScrollingDown {
newHeight = max(self.minHeaderHeight, self.searchBarHeightConstraint.constant - abs(scrollDiff))
} else if isScrollingUp {
newHeight = min(self.maxHeaderHeight, self.searchBarHeightConstraint.constant + abs(scrollDiff))
newSearchBar.showsScopeBar = false
}
if newHeight != self.searchBarHeightConstraint.constant {
self.searchBarHeightConstraint.constant = newHeight
self.setScrollPosition(position: self.previousScrollOffset)
}
self.previousScrollOffset = scrollView.contentOffset.y
{
I'm having an issue when my table view cell rendering image for the first time, the header seems to be stretched suddenly right just before the table view was about to display that image cell. It's happened to be tableview's contentOffset get changed somehow in this case when rendering image.I'm having self-sizing table view cell implemented by the way.
Any ideas what's going on? Thanks a lot for your elegant tutorial.
Hey! This is a great project you worked on but I found one issue. I changed numberOfRowsInSection
to return 5. Now if you try collapse the header, nothing will happen.
Thanks again for the awesome blog post ๐
ANy ideas on how to make it so that when you scroll to the top, you dont expand the header until you get closer to the top, and the content comes out from under the header?
Hello John,
I found one issue in UITableview . By default you disabled estimate automatic in uitableview property in storyboard. But in my project that option was enabled. when i will move to other screen and whne i am coming back to previous screen that time i am reloading tableview in viewwillappear. that time my header is bouncing when scrolling time.
Note: Before pushing you just scroll at bottom. then navigate to other screen. when you are coming back to auto header screen and scroll tableview that time you will come to know issue.
Thanks.
Hello,
if the tableview has 2-3 rows, the header will not expand
I tried adding the footerView. When the header is expanded and just scroll the tableview and can view the footerView , but when I try collapsing the header i.e, the tableView is expanded completely , the footerView is not viewed.
Edit:
This one returns a sticky footer view, which I don't want.
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { return myView }
and this one return at the last, but not viewing properly.
self.tableView.tableFooterView = myView
Check the image here http://imgur.com/a/sNKkY
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.