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.
In Example folder you can launch pod install
and open Example.xcworkspace
Use PresentWithAnimatorSegue
in your storyboard or use one of already configured segue: SlideDownSegue
, SlideUpSegue
, SlideLeftSegue
, SlideRightSegue
, ChildWindowSegue
, ...
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(...))
}
}
π‘ You can also put your own custom animator.
if let segue = segue as? PresentWithAnimatorSegue {
segue.animator = MyAnimator()
}
Replace contentViewController
of sourceController
parent NSWindow
by destinationController
π‘ You can store this segue into destinationController
and call unperform
on it to restore sourceController
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.
Segue to dismiss current from controller
Allow to display in storyboard the action as segue instead of simple IBAction
Segue using parent controller of source and transitionFromViewController
function
parentViewController
must be set and the same for the sourceController
and destinationController
Show destinationController
in a popover with a position relative to the selected table row
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
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
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.
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.