I have a custom view as my collection view header. But of course when I scroll, the header disappears until I scroll back to the top.
An example of what I want to achieve is like the current Facebook app. Where the "LIVE, Photo, Check in" view hides when you scroll down, and returns once you scroll upwards a bit.
It's like this. But I just want the live, photo and check in bar hidden and show while scroll.
My current approach is just add as a collection view header.
What you need to do is lock the view from animating once an animation is in progress and open it up once it is completed.
The scroll view displays its content within the scrollable content region. As the user performs platform-appropriate scroll gestures, the scroll view adjusts what portion of the underlying content is visible. ScrollView can scroll horizontally, vertically, or both, but does not provide zooming functionality.
Here is code for hiding navigation bar with scroll
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
//
contentOffSet = self.channelsCollView.contentOffset.y;
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
//
let scrollPos = self.channelsCollView.contentOffset.y ;
if(scrollPos >= contentOffSet ){
//Fully hide your toolbar
UIApplication.shared.isStatusBarHidden = true
UIView.animate(withDuration: 0.5, animations: {
//
//write a code to hide
self.navigationController?.isNavigationBarHidden = true
}, completion: nil)
} else {
//Slide it up incrementally, etc.
UIApplication.shared.isStatusBarHidden = false
UIView.animate(withDuration: 0.5, animations: {
//
self.navigationController?.isNavigationBarHidden = false
}, completion: nil)
}
}
You can use these libraries, which manages hiding and showing of Navigation bar as user scrolls :
Another way is to use this function in your viewWillAppear
if let navigationController = self.navigationController as? ScrollingNavigationController {
navigationController.followScrollView(tableView, delay: 30.0)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With