CollectionViewPreviewController

open class CollectionViewPreviewController : CollectionViewController, CollectionViewDelegatePreviewLayout

An easy to use CollectionViewController that transitions from a source collection view.

Presentation & Data

The controller is presented from a source collection view. The data source of the source collection view is used to load data for the preview collection view. The preview controller will act as a proxy between the preview collection view and your source colleciton views data source.

Important

The data source for the collection view passed to present(in:) must conform to CollectionViewPreviewControllerDelegate

Transitions

The preview controller manages the transitions to and from the source and allows the preview cell to customize the transition.

Although the The preview controller will accept any cell class, supporting transitions requires a small amount of additional setup.

The simplest way to support transitions is to create your subclass from CollectionViewPreviewCell. CollectionViewPreviewCell will animate the frame of the cell from the source and back.

For custom transitions, if you subclass CollectionViewPreviewCell you can simply override the the transition methods, otherwise conform your CollectionViewCell subclass and implement the methods yourself. See CollectionViewPreviewTransitionCell for more about how to implement custom transitions

  • The background color of the view when the items are displayed

    Declaration

    Swift

    open var backgroundColor: NSColor { get set }
  • The collection view the receiver was presented from

    Declaration

    Swift

    private(set) public var sourceCollectionView: CollectionView?
  • The index path the receiver was presented from

    Declaration

    Swift

    private(set) public var sourceIndexPath: IndexPath?
  • The index path for the currently displayed item

    Declaration

    Swift

    public var currentIndexPath: IndexPath? { get }
  • The duration of present/dismiss transitions

    Declaration

    Swift

    open var transitionDuration: TimeInterval
  • Present the preview controller, transitioning from an item at indexPath in the source collectionView

    Data Source

    The DataSource of the preview collection view will the same as the provided source collection view.

    Excluding items from preview

    Because the preview collection view must share a data source with it’s source, it can be useful to keep some items displayed in the source from being previewed. See collectionViewPreviewController(_:canPreviewItemAt:) in CollectionViewPreviewControllerDelegate

    Declaration

    Swift

    open func present(in controller: NSViewController, source sourceCollectionView: CollectionView, indexPath: IndexPath, completion: AnimationCompletion? = nil)

    Parameters

    controller

    The ViewController to present in

    sourceCollectionView

    A collectionView to transition from

    indexPath

    The index path of the item to transition with

    completion

    A block to call when the transition is complete

  • Dismiss the preview controller, transitioning the current item back to its source

    Declaration

    Swift

    open func dismiss(animated: Bool, completion: AnimationCompletion? = nil)

    Parameters

    animated

    If the dismiss should be animated

    completion

    A block to call when the tranision is complete