GithubHelp home page GithubHelp logo

lerist / amscrollingnavbar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andreamazz/amscrollingnavbar

0.0 3.0 0.0 22.75 MB

Scrollable UINavigationBar that follows the scrolling of a UIScrollView

License: MIT License

Ruby 0.44% Objective-C 29.77% Swift 64.89% Shell 4.90%

amscrollingnavbar's Introduction

CocoaPods Build Status codecov.io Carthage compatible Swift 2.2 Join the chat at https://gitter.im/andreamazz/AMScrollingNavbar Donate

A custom UINavigationController that enables the scrolling of the navigation bar alongside the scrolling of an observed content view

Versioning notes

Version 2.x is written as a subclass of UINavigationController, in Swift.
Version 2.0.0 introduce Swift 2.0 syntax. Checkout 2.0.0.beta for Swift 1.2.
If you are looking for the category implementation in Objective-C, make sure to checkout version 1.x and prior, although the 2.x is recomended.

#Screenshot

#Setup with CocoaPods

pod 'AMScrollingNavbar'

use_frameworks!

#Setup with Carthage

github "andreamazz/AMScrollingNavbar"

##Usage

Make sure to use a subclass of ScrollingNavigationController for your UINavigationController. Either set the class of your UINavigationController in your storyboard, or create programmatically a ScrollingNavigationController instance in your code.

Use followScrollView(_: delay:) to start following the scrolling of a scrollable view (e.g.: a UIScrollView or UITableView). ####Swift

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    if let navigationController = navigationController as? ScrollingNavigationController {
        navigationController.followScrollView(tableView, delay: 50.0)
    }
}

####Objective-C

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [(ScrollingNavigationController *)self.navigationController followScrollView:self.tableView delay:50.0f];
}

Use stopFollowingScrollview() to stop the behaviour. Remember to call this function on disappear:

override func viewDidDisappear(animated: Bool) {
    super.viewDidDisappear(animated)

    if let navigationController = navigationController as? ScrollingNavigationController {
        navigationController.stopFollowingScrollView()
    }
}

##ScrollingNavigationViewController To DRY things up you can let your view controller subclass ScrollingNavigationViewController, which provides the base setup implementation. You will just need to call followScrollView(_: delay:):

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    if let navigationController = navigationController as? ScrollingNavigationController {
        navigationController.followScrollView(tableView, delay: 50.0)
    }
}

##ScrollingNavigationControllerDelegate You can set a delegate to receive a call when the state of the navigation bar changes:

if let navigationController = navigationController as? ScrollingNavigationController {
    navigationController.scrollingNavbarDelegate = self
}

Delegate function:

func scrollingNavigationController(controller: ScrollingNavigationController, didChangeState state: NavigationBarState) {
    switch state {
    case .Collapsed:
        print("navbar collapsed")
    case .Expanded:
        print("navbar expanded")
    case .Scrolling:
        print("navbar is moving")
    }
}

##Handling navigation If the view controller with the scroll view pushes new controllers, you should call showNavbar(animated:) in your viewWillDisappear(animated:):

override func viewWillDisappear(animated: Bool) {
  super.viewWillDisappear(animated)
    if let navigationController = navigationController as? ScrollingNavigationController {
      navigationController.showNavbar(animated: true)
    }
}

##Scrolling to top When the user taps the status bar, by default a scrollable view scrolls to the top of its content. If you want to also show the navigation bar, make sure to include this in your controller:

override func scrollViewShouldScrollToTop(scrollView: UIScrollView) -> Bool {
    if let navigationController = navigationController as? ScrollingNavigationController {
        navigationController.showNavbar(animated: true)
    }
    return true
}

Check out the sample project for more details.

#Author Andrea Mazzini. I'm available for freelance work, feel free to contact me.

Want to support the development of these free libraries? Buy me a coffee โ˜•๏ธ via Paypal.

#Contributors Syo Ikeda and everyone kind enough to submit a pull request.

#MIT License The MIT License (MIT)

Copyright (c) 2016 Andrea Mazzini

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

amscrollingnavbar's People

Contributors

abeansits avatar allewun avatar andreamazz avatar apiyron avatar dabeck avatar erikackermann avatar genadyo avatar gitter-badger avatar igor-palaguta avatar ikesyo avatar jeffreyjackson avatar m1entus avatar mrdaios avatar neoplastic avatar readmecritic avatar vvit avatar xzenon avatar zzz6519003 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.