CustomSegue
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 prepare(for segue
function.
class MyViewController: NSViewController {
override func prepare(for segue: NSStoryboardSegue, sender: AnyObject?) {
if segue.identifier?.rawValue == "PetDetail" {
...
You can use Natalie to generate code about segue for your controller. With this generate code you can do
override func prepare(for segue: NSStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "PetDetail" {
// or better the constant generated
if segue == MyViewController.Segue.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(...))
}
}
if let segue = segue as? PresentWithAnimatorSegue {
segue.animator = MyAnimator()
}
Others segues
ReplaceWindowContentSegue
Replace contentViewController
of sourceController
parent NSWindow
by destinationController
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
tableView
into segue object (do it in prepareForSegue
)
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.
-
Add the project to your Podfile.
use_frameworks! pod 'CustomSegue'
-
Run
pod install
and open the.xcworkspace
file to launch Xcode.
Using Carthage
Carthage is a decentralized dependency manager for Objective-C and Swift.
-
Add the project to your Cartfile.
github "phimage/CustomSegue"
-
Run
carthage update
and follow the additional steps in order to add Prephirences to your project.