Coder Social home page Coder Social logo

ck-navigation's Introduction

CKNavigationController

A UINavigationController port for Cocoa development

Including CKNavigation

To integrate CKNavigation into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :osx, '10.12'

target 'TargetName' do
  pod 'CKNavigation', '~> 0.1.1'
end

Usage

The CKNavigationController is meant to provide navigation in a single NSWindow similar to that of UIKit's UINavigationController on iOS. This is a great solution for seperating views in low profile status bar apps and the like.

Implementing a CKNavigationController is exactly like UINavigationController in iOS. Simply call the initializer and pass in the controller you'd like to set as root. Note: in order to add a view controller to a navigation controller, the view controller must subclass CKNavigatableViewController or explicitly conform to the CKNavigatable protocol.

import CKNavigation

let myController = MyViewController()
let myNavigationController = CKNavigationController(rootViewController: myController)

This approach is well suited for programmatic user interfaces. You could simply create an NSWindow instance, and add your navigation controller as a subview.

import Foundation
import Cocoa
import CKNavigation

class AppDelegate: NSObject, NSApplicationDelegate {

    var navigationController: CKNavigationController!
    
    let controller = ViewController()
    
    let window: NSWindow {
        let content = NSRect(x: 0, y: 0, width: 500, height: 500)
        let window = NSWindow(contentRect: content, styleMask: .closable, backing: .buffered, defer: false)
        return window
    }()
    
    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // initialize navigation controller with root view
        navigationController = CKNavigationController(rootViewController: controller)
        // add navigation controller to the window
        window.contentView?.addSubview(navigationController.view)
        navigationController.view.wantsLayer = true
        window.makeKeyAndOrderFront(nil)
    }
}

Pushing a view controller to the stack is done easily, too. From inside the myViewController class:

    @objc func handleNextButtonPress(_ sender: Any?) {
          let newController = AnotherViewController()
          self.navigationController!.pushViewController(newController)
    }

Similarly, to pop a view controller from the stack:

    @objc func handlePreviousButtonPress(_ sender: Any?) {
          self.navigationController!.popViewController()
    }

Example

The example that you see in the demo gif, at the top is available here. This implementation was 100% programmatic.

License

MIT © Charles Kenney

ck-navigation's People

Contributors

0xch4z avatar

Watchers

 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.