KKBOX WWDC17 UIKit Drag and Drop - Mario

Post on 22-Jan-2018

2.060 views 0 download

Transcript of KKBOX WWDC17 UIKit Drag and Drop - Mario

Drag and Drop in iOS 11

Mario TungKKTV

Summary- Goals for drag and drop- Different phases of a drag session- Essential Functions- Drag delegates- Drop delegates- Next step

What is drag and drop?A way to move data around

Goals for Drag and DropResponsive

- On demand / Async data transfer

Secure

- Source app can choose what data to transfer / who to transfer to- Data is only visible to destination

Great multi touch experience

- Deep integration with iOS apps- Multiple types of touch/gestures can be used

Demo

Phases of a drag session

Data transfer time depends on file size

Drag begins: get data items

- Use UIDragItems for transferring data- NSItemProvider only allows objects (not string structs)

Get drop proposal during session update

- Called when touch point has moved in view / additional items are added- Return what to do when user drops item now- 4 types of UIDropOperations (Cancel / Copy / Move / Forbidden)- Move operation is only allowed within the same app

Perform the drop

- Perform data transfer of objects

Customizing Drag and Drop- Use the drag interaction delegate to find out when views are lifted / being

dragged around

- Use drop interaction delegate to find out when an item has entered view / dropped into view

Drag interaction delegate - Lift

- View to be shown when dragging

Drag interaction delegate - Session begins and moves

Drag interaction delegate - Adding more items

- Add additional items to drag session- Update preview view accordingly

Drag interaction delegate - End session

- Session is going to end with one of the four types of UIDropOperation

Drag interaction delegate - End session (Cancel)

Drag interaction delegate - End session (Copy/Move)

Drop interaction delegates

Drop interaction delegate - Session enters view

- Can be used to filter out types of data that are accepted

Drop interaction delegate - Session enters/exits view

- Enter/update/exit can happen multiple times - delegates will keep getting called

Drop interaction delegate - Drop animations

- Execute any further UI changes to the UITargetedDragPreview from previewForLifting

Next step - exploring more