Skip to content

A header and footer toggle display-state depending on the scroll or time interval

License

Notifications You must be signed in to change notification settings

recruit-lifestyle/AutoToggleHeaderFooterView

Repository files navigation

AutoToggleHeaderFooterView

Version License Platform

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

Requirements

  • iOS 8.0+
  • Swift 3.0.2

Gif

movie

Try Demo

You can try Demo app quickly.

$ pod try 'AutoToggleHeaderFooterView'

Usage

Require

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
}

TableView Example

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)
}

WebView Example

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/")!))
}

Change options

public var isTimerEnabled = true
public var isScrollHeaderFooterEnabled = true
public var showAnimationDuration = TimeInterval(0.5)
public var autoShowTimeInterval = TimeInterval(3.0)

Installation

AutoToggleHeaderFooterView is available through CocoaPods or Carthage.

CocoaPods

pod "AutoToggleHeaderFooterView"

Carthage

github "recruit-lifestyle/AutoToggleHeaderFooterView"

Credits

AutoToggleHeaderFooterView is owned and maintained by RECRUIT LIFESTYLE CO., LTD.

AutoToggleHeaderFooterView was originally created by Tomoya Hayakawa

License

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.

About

A header and footer toggle display-state depending on the scroll or time interval

Resources

License

Stars

Watchers

Forks

Packages

No packages published