Comparing NSCollectionView and UICollectionView #3

Harry Ng
macOS App Development
2 min readOct 20, 2016
Photo by Ilya Pavlov

The biggest difference for NSCollectionView in macOS is the support of Drag & Drop. It is served through a set of NSCollectionViewDelegate methods.

Drag & Drop Support

In macOS, keyboard and mouse (including TrackPad and Magic Mouse) are the most common forms of input. Drag & Drop is based on the mouse control. User can do the followings:

  1. Drag a rectangle to highlight the items within the area
  2. Drag the selected items to a different position within the collection view
  3. Drag the selected items to anywhere else that allows drop, both within and outside the application

Typically, Drag & Drop will go through a life cycle as below:

  1. Create a Pasteboard to hold the dragging data
  2. Check whether the drag can start
  3. Start a dragging session
  4. Validate the Drop in an area
  5. Accept the Drop
  6. End a dragging session

Each of these lifecycle methods has a corresponding delegate method.

Here is a video demonstrating a simple use of Drag & Drop in NSCollectionView.

Layout Handling in UICollectionView

In comparison, iOS provides more delegate APIs to handle layout changes. There are 4main categories

  • Tracking the Addition and Removal of Views
  • Handling Layout Changes
  • Managing Actions for Cells
  • Managing Focus in a Collection View

If you want to implement something like Drag & Drop, a long press together with a pan gesture would be a nice place to get started.

--

--