Comparing NSCollectionView and UICollectionView #3
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:
- Drag a rectangle to highlight the items within the area
- Drag the selected items to a different position within the collection view
- 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:
- Create a Pasteboard to hold the dragging data
- Check whether the drag can start
- Start a dragging session
- Validate the Drop in an area
- Accept the Drop
- 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.
I am taking a challenge to write a post every day for 180 days. The content will be related to my life as a father, entrepreneur, developer and trainer.