Giter Site home page Giter Site logo

dworak / customsegue Goto Github PK

View Code? Open in Web Editor NEW

This project forked from phimage/customsegue

0.0 1.0 0.0 435 KB

Custom segue for OSX Storyboards with slide and cross fade effects (NSViewControllerTransitionOptions)

License: MIT License

Ruby 4.15% Objective-C 1.08% Swift 94.77%

customsegue's Introduction

CustomSegue

License Platform Language Issues Cocoapod

Custom segue for OSX Storyboards. Slide and cross fade effects, new customized window.

class MyViewController: NSViewController {

  override func prepareForSegue(segue: NSStoryboardSegue, sender: AnyObject?)
      if segue.identifier == "configured" {
          if let segue = segue as? PresentWithAnimatorSegue, animator = segue.animator as? TransitionAnimator {
              animator.duration = 1
              animator.transition = [.SlideDown, .Crossfade]
          }
      }
  }

TransitionAnimator transition is configured via NSViewControllerTransitionOptions, and suppress the need to use a parent controller with transitionFromViewController function.

Demo

In Example folder you can launch pod install and open Example.xcworkspace

How to use

Use PresentWithAnimatorSegue in your storyboard or use one of already configured segue: SlideDownSegue, SlideUpSegue, SlideLeftSegue, SlideRightSegue, ChildWindowSegue, ...

Configure segue

In your storyboard add an storyboard identifier to the segue.

Then in your source view controller, you can configure the segue in prepareForSegue function.

class MyViewController: NSViewController {
  override func prepareForSegue(segue: NSStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "PetDetail" {
    ...

You can change the duration, the transition type, ... on animator object of type TransitionAnimator

if let segue = segue as? PresentWithAnimatorSegue, animator = segue.animator as? TransitionAnimator {
  animator.duration = 1
  animator.transition = [.SlideDown, .Crossfade]
}

For ChildWindowSegue you can customize the NSWindow, which display the destination controller

if let segue = segue as? ChildWindowSegue, animator = segue.animator as? ChildWindowAnimator {
    animator.windowCustomizer = { window in
      window.styleMask = NSBorderlessWindowMask
      window.setFrameOrigin(NSPoint(...))
    }
}

๐Ÿ’ก You can also put your own custom animator.

if let segue = segue as? PresentWithAnimatorSegue {
  segue.animator = MyAnimator()
}

Others segues

ReplaceWindowContentSegue

Replace contentViewController of sourceController parent NSWindow by destinationController

๐Ÿ’ก You can store this segue into destinationController and call unperform on it to restore sourceController

SplitViewSegue

Segue that replace the last split view item or add a new one into the sourceController parent (NSSplitViewController)

Set replace to false on segue, to add a new split view item.

DismissSegue

Segue to dismiss current from controller

Allow to display in storyboard the action as segue instead of simple IBAction

TransitionFromViewSegue

Segue using parent controller of source and transitionFromViewController function

โš ๏ธ parentViewController must be set and the same for the sourceController and destinationController

TablePopoverSegue

Show destinationController in a popover with a position relative to the selected table row

โš ๏ธ You must set the tableView into segue object (do it in prepareForSegue)

๐Ÿ’ก You can display detail about selected row in a nice way. So in prepareForSegue get table view selected row and pass data to destinationController

Present view controller utility method

Little utility method added to NSViewController using new enum PresentationMode.

viewController.present(.AsSheet)
viewController.present(.AsModalWindow)
viewController.present(.Segue(segueIdentifier: "id"))
viewController.present(.Animator(animator: MyAnimator()))
viewController.present(.AsPopover(...

โš ๏ธ parentViewController must be set

Installation

Using CocoaPods

CocoaPods is a centralized dependency manager for Objective-C and Swift. Go here to learn more.

  1. Add the project to your Podfile.

    use_frameworks!
    
    pod 'CustomSegue'
  2. Run pod install and open the .xcworkspace file to launch Xcode.

Using Carthage

Carthage is a decentralized dependency manager for Objective-C and Swift.

  1. Add the project to your Cartfile.

    github "phimage/CustomSegue"
    
  2. Run carthage update and follow the additional steps in order to add Prephirences to your project.

customsegue's People

Contributors

phimage 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.