Scroll to hide/show custom header view using TableView OR ScrollView
.
- Xcode 9.0+
- iOS 10+
- Swift 4.0+
MJHeaderViewHideShow will be used via interface builder.
-
Add Custom View
(UIView)
at the top in your interface builder. AddMJHeaderAnimation
inClass
property at Identity Inspector of added view. -
You've to add
Height
constraint to your Custom View, don't add identifier to it, library will detect height automatically.
Use following properties to edit it's default functionality. Add your settings in viewDidLoad
.
// declare instance of KJNavigationViewAnimation by connecting it to UIView outlet in interface builder
@IBOutlet weak var viewTop: MJHeaderAnimation!
override func viewDidLoad() {
super.viewDidLoad()
// Hide default NavigationBar
self.navigationController?.isNavigationBarHidden = true
//Parameter details
// 1. UITableView instance
// 2. Title Optional with ""
// 3. Minimum header view hieght
self.viewTop.initializationTopViewSettings(self.tblView, "Manoj", 44)
}
You have to extend your viewController
class with UIScrollViewDelegate
, and connect TableView delegate to self
. Last step to call MJHeaderAnimation scrollview methods
as below from UIScrollViewDelegate delegate methods
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
// MJHeaderView is my declared MJHeaderViewHideShow property in ViewController class
viewTop.scrollViewDidScroll(scrollView)
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
viewTop.scrollViewDidEndDecelerating(scrollView)
}
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
viewTop.scrollViewDidEndDragging(scrollView, willDecelerate: decelerate)
}
}
TopHeaderViewHideShow
is available under the MIT license. See the LICENSE file for more info.