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

Related tags

UI CustomSegue
Overview

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 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()
}

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.

You might also like...
Fetch the star wars api from all the planets and list and show details using Swift UI and Combine

Star Wars Planets Fetch the star wars planet data by using stat war api, list and show details using SwiftUI and Combine frameworks πŸ”– Swift UI Framew

🏞 A simple iOS photo and video browser with optional grid view, captions and selections written in Swift5.0
🏞 A simple iOS photo and video browser with optional grid view, captions and selections written in Swift5.0

Introduction 🏞 MediaBrowser can display one or more images or videos by providing either UIImage objects, PHAsset objects, or URLs to library assets,

MZFormSheetPresentationController provides an alternative to the native iOS UIModalPresentationFormSheet, adding support for iPhone and additional opportunities to setup UIPresentationController size and feel form sheet.
MZFormSheetPresentationController provides an alternative to the native iOS UIModalPresentationFormSheet, adding support for iPhone and additional opportunities to setup UIPresentationController size and feel form sheet.

MZFormSheetPresentationController MZFormSheetPresentationController provides an alternative to the native iOS UIModalPresentationFormSheet, adding sup

Step-by-step progress view with labels and shapes. A good replacement for UIActivityIndicatorView and UIProgressView.
Step-by-step progress view with labels and shapes. A good replacement for UIActivityIndicatorView and UIProgressView.

StepProgressView Step-by-step progress view with labels and shapes. A good replacement for UIActivityIndicatorView and UIProgressView. Usage let progr

High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton, Promise and more.

SwiftyUI High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton and more. Features SwiftyView GPU rendering Image and Color

UIPheonix is a super easy, flexible, dynamic and highly scalable UI framework + concept for building reusable component/control-driven apps for macOS, iOS and tvOS
UIPheonix is a super easy, flexible, dynamic and highly scalable UI framework + concept for building reusable component/control-driven apps for macOS, iOS and tvOS

UIPheonix is a super easy, flexible, dynamic and highly scalable UI framework + concept for building reusable component/control-driven apps for macOS, iOS and tvOS

BulletinBoard is an iOS library that generates and manages contextual cards displayed at the bottom of the screen
BulletinBoard is an iOS library that generates and manages contextual cards displayed at the bottom of the screen

BulletinBoard is an iOS library that generates and manages contextual cards displayed at the bottom of the screen. It is especially well

Fashion is your helper to share and reuse UI styles in a Swifty way.
Fashion is your helper to share and reuse UI styles in a Swifty way.

Fashion is your helper to share and reuse UI styles in a Swifty way. The main goal is not to style your native apps in CSS, but use a set

Beautiful flag icons for usage in apps and on the web.
Beautiful flag icons for usage in apps and on the web.

FlagKit Beautiful flag icons for usage in apps and on the web. All flags are provided as stand-alone PNG and SVG files. FlagKit also provides an Asset

Comments
  • CustomSegue not showing up in IB module dropdown

    CustomSegue not showing up in IB module dropdown

    Hi,

    I've built the Demo project successfully and in the Storyboard, I see that each segue has a custom class assigned to it successfully (in the attributes inspector). However, in my project I can't type it (it doesn't autocomplete) and the module dropdown below is empty as well.

    I can import CustomSegue fine in a Swift file but not in the IB.

    How did you get it working in the Demo project? Btw, I'm using Cocoapods. I tried Carthage but had the same issue.

    Thanks for your help and for writing this much needed code. Ivan

    opened by ivanmkc 2
  • Update for Swift 5 and add swift version to podspec

    Update for Swift 5 and add swift version to podspec

    Hey,

    With xcode 10 out and since podspec doesn't specify swift version, swift 5 is being used by default which leads to compilation problems.

    I can manually change pod's swift version, but it would have been better to either:

    • have support for swift 5
    • and/or have swift version specified in podspec.

    Thanks

    opened by undsoft 1
  • pod install is error

    pod install is error

    $pod --version 1.3.1 $git clone https://github.com/phimage/CustomSegue.git $cd CustomSegue/Example [!] Unable to satisfy the following requirements:

    • CustomSegue (from../CustomSegue.podspec) required by Podfile

    Specs satisfying the CustomSegue (from../CustomSegue.podspec) dependency were found, but they required a higher minimum deployment target.

    opened by kkfd008 0
  • View controllers below the current view controller are receiving click events

    View controllers below the current view controller are receiving click events

    Hi,

    When I click a cell on my table view controller, it opens up a new screen using your a SlideLeftSegue. However on this new screen, when I click an empty spot, the cells underneath it receive the click and segues again.

    Why does the screen below still get click events and how do I prevent this?

    Many thanks, Ivan

    opened by ivanmkc 1
Owner
Eric Marchand
πŸ§™πŸΊπŸ₯ŠπŸ₯‹πŸ“
Eric Marchand
Show the weather effects onto view written in Swift4.2

URWeatherView What is this for? Showing some kinds of the weather effect, written in Swift4.2. This code style is the Protocol Oriented Programming. T

Urtaq 449 Dec 28, 2022
SwiftCrossUI - A cross-platform SwiftUI-like UI framework built on SwiftGtk.

SwiftCrossUI A SwiftUI-like framework for creating cross-platform apps in Swift. It uses SwiftGtk as its backend. This package is still quite a work-i

null 97 Dec 28, 2022
A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView and iPhone X safe area support for content reloading. Built for iOS 10 and later.

Arale A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView support for reloading your content. Built f

Putra Z. 43 Feb 4, 2022
Custom emojis are a fun way to bring more life and customizability to your apps.

Custom emojis are a fun way to bring more life and customizability to your apps. They're available in some of the most popular apps, such as Slack, Di

Stream 244 Dec 11, 2022
Kit for building custom gauges + easy reproducible Apple's style ring gauges.

GaugeKit ##Kit for building custom gauges + easy reproducible Apple's style ring gauges. -> Example Usage Open GaugeKit.xcworkspace and change the sch

Petr Korolev 1k Dec 23, 2022
A custom reusable circular / progress slider control for iOS application.

HGCircularSlider Example To run the example project, clone the repo, and run pod install from the Example directory first. You also may like HGPlaceho

Hamza Ghazouani 2.4k Jan 6, 2023
Custom Beautiful UIView For Handling IDs in iOS

IDView Custom Beautiful UIView For Handling IDs in iOS Setup Set the placeholder images for the front and back faces. override func viewDidLoad()

Omar Labib 6 Aug 21, 2021
iOS custom controller used in Jobandtalent app to present new view controllers as cards

CardStackController iOS custom controller used in the Jobandtalent app to present new view controllers as cards. This controller behaves very similar

jobandtalent 527 Dec 15, 2022
DGFadingLabel - A custom UILabel that fades away the end of your text when text is too large to fit within the label's frame

A custom UILabel that fades away the end of your text when text is too large to fit within the label's frame.

donggyu 4 Jun 10, 2022
A custom UIControl which functions like UISlider where you can set multiple intervals with different step values for each interval.

MultiStepSlider A custom UIControl which functions like UISlider where you can set multiple intervals with different step values for each interval. Th

Susmita Horrow 25 Apr 28, 2022