Comments (6)
I needed it to work in this way and used a different solution.
In the canAnimateHeader
method, I just checked if current scroll position is greater than the point you want it to remain collapsed. If it is then just do nothing at all, if it isn't then, animate the header.
private func canAnimateHeader(forScrollView scrollView: UIScrollView) -> Bool {
if scrollView.contentOffset.y >= alwaysCollapsedScrollOffset {
return false
}
// isContentToScroll is same as previous implementation,
// I just broke it up a little
return isContentToScroll(forScrollView: scrollView)
}
private func isContentToScroll(forScrollView scrollView: UIScrollView) -> Bool {
let headerSize = headerHeight - headerHeightMinimum
let scrollViewMaxHeight = scrollView.frame.height + headerSize
return scrollView.contentSize.height > scrollViewMaxHeight
}
from animatingtableviewheader.
Figured this out.
from animatingtableviewheader.
How did you do it?
from animatingtableviewheader.
@escully27 Sorry misunderstood your question.
I did it like this.
First set a scrolling position.
if isScrollingDown {
currentScrollingDirection = ScrollingDirection.down
self.navigationController?.setNavigationBarHidden(true, animated: true)
} else if isScrollingUp {
currentScrollingDirection = ScrollingDirection.up
}
Then,
if scrollView.contentOffset.y <= 20 {
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
if canAnimateHeader(scrollView) {
self.previousScrollOffset = scrollView.contentOffset.y
// Dont do anything if were not above a certain height and we are scrolling up
if scrollView.contentOffset.y >= 120 && currentScrollingDirection == ScrollingDirection.up {
return
}
// Calculate new header height
let newHeight = self.getNewConstraintValue(constraint: self.extendedNavBarHeightConstraint, valueMin: self.minHeaderHeight, valueMax: self.maxHeaderHeight, scrollDiff: scrollDiff)
// Header needs to animate
if newHeight != self.extendedNavBarHeightConstraint.constant {
self.extendedNavBarHeightConstraint.constant = newHeight
self.setScrollPosition(self.previousScrollOffset)
}
self.emailLabelWidthConstraint.constant = self.getNewConstraintValue(constraint: self.emailLabelWidthConstraint, valueMin: self.minEmailWidth, valueMax: self.maxEmailWidth, scrollDiff: scrollDiff)
self.emailLabelHeightConstraint.constant = self.getNewConstraintValue(constraint: self.emailLabelHeightConstraint, valueMin: self.minEmailHeight, valueMax: self.maxEmailHeight, scrollDiff: scrollDiff)
self.imageViewWidthConstraint.constant = self.getNewConstraintValue(constraint: self.imageViewWidthConstraint, valueMin: self.minImageViewWidth, valueMax: self.maxImageViewWidth, scrollDiff: scrollDiff)
self.imageViewHeightConstraint.constant = self.getNewConstraintValue(constraint: self.imageViewHeightConstraint, valueMin: self.minImageViewHeight, valueMax: self.maxImageViewHeight, scrollDiff: scrollDiff)
self.supportTopConstraint.constant = self.getNewConstraintValue(constraint: self.supportTopConstraint, valueMin: self.minSupportTop, valueMax: self.maxSupportTop, scrollDiff: scrollDiff)
self.emailTopConstraint.constant = self.getNewConstraintValue(constraint: self.emailTopConstraint, valueMin: self.minEmailTop, valueMax: self.maxEmailTop, scrollDiff: scrollDiff)
}
from animatingtableviewheader.
I wrote a utilty function as well called getNewConstraintValue
func getNewConstraintValue(constraint: NSLayoutConstraint, valueMin: CGFloat, valueMax: CGFloat, scrollDiff: CGFloat) -> CGFloat {
switch currentScrollingDirection {
case .down:
return max(valueMin, constraint.constant - abs(scrollDiff))
case .up:
return min(valueMax, constraint.constant + abs(scrollDiff))
case .none:
return constraint.constant
}
}
from animatingtableviewheader.
Thanks for the response. Not working for me.. I have no navigation bar involved so it's behaving in a worse way than original. Cheers
from animatingtableviewheader.
Related Issues (8)
- Bug with 2-3 rows HOT 2
- Search Bar does not always expand HOT 3
- FooterView not working HOT 3
- Laggy header when scrolling tableview with image cell HOT 4
- isScrollingDown and isScrollingUp - appear in revserse HOT 4
- Header Bouncing when table reload HOT 8
- Header late to expand upon scroll up when table view has bottom layout margins or content inset
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from animatingtableviewheader.