A view which can control the behavior of the header and footer depending on the conditions like
- the distance a user scrolls the view over
- the duration a user do no action for
- iOS 8.0+
- Swift 3.0.2
You can try Demo app quickly.
$ pod try 'AutoToggleHeaderFooterView'
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// If scrollview under the translucent NavigationBar, use this.
autoToggleView.register(scrollView: tableView)
}
// UIScrollViewDelegate
func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
autoToggleView.showHeaderFooter(withDuration: 0.3)
return true
}
override func viewDidLoad() {
super.viewDidLoad()
// Initialize with any header or footer
let autoToggleView = AutoToggleHeaderFooterView(header: header, footer: footer)
autoToggleView.addScrollView(tableView)
// Add to any view
view.addSubview(autoToggleView)
// If scrollview under the translucent NavigationBar, use this.
// And call `AutoToggleHeaderFooterView.register(scrollView:) at `viewDidLayoutSubviews`.
autoToggleView.makeEdgesEqualToSuperview()
// Or not under the NavigationBar
// automaticallyAdjustsScrollViewInsets = false
// makeEdgesFitToLayoutGuide(view: autoToggleView)
}
override func viewDidLoad() {
super.viewDidLoad()
let autoToggleView = AutoToggleHeaderFooterView(header: header, footer: footer)
autoToggleView.addSubview(self.webView)
autoToggleView.register(scrollView: self.webView.scrollView)
automaticallyAdjustsScrollViewInsets = false
view.addSubview(autoToggleView)
makeEdgesFitToLayoutGuide(view: autoToggleView)
webView.makeEdgesEqualToSuperview()
webView.load(URLRequest(url: URL(string: "https://www.recruit-lifestyle.co.jp/")!))
}
public var isTimerEnabled = true
public var isScrollHeaderFooterEnabled = true
public var showAnimationDuration = TimeInterval(0.5)
public var autoShowTimeInterval = TimeInterval(3.0)
AutoToggleHeaderFooterView is available through CocoaPods or Carthage.
pod "AutoToggleHeaderFooterView"
github "recruit-lifestyle/AutoToggleHeaderFooterView"
AutoToggleHeaderFooterView is owned and maintained by RECRUIT LIFESTYLE CO., LTD.
AutoToggleHeaderFooterView was originally created by Tomoya Hayakawa
Copyright 2017 RECRUIT LIFESTYLE CO., LTD.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.