Search code examples
iosipaddrag-and-dropios13multi-window

How to create a new UIWindowScene from drag'n'drop?


I'm trying to implement the new multi-window in iPadOS, and I struggle with drag'n'drop.

In this WWDC video they show us an example where a new scene is created after draging a mail to the side of the screen (at 11:45).

How can we do that? In the few other videos on the subject, they always create a new scene by tapping a button and calling appdelegate's requestSceneSessionActivation.

Does anybody knows how to create a new scene like in the video?


Solution

  • If you go to the WWDC 2019 Session 212 page, there is a link to the Supporting Multiple Windows on iPad sample app that goes with the video. This is the Gallery app they demonstrate including the code to create a new scene via drag and drop.

    The basic idea is to create an NSUserActivity representing enough data to create the new scene.

    In the appropriate drag delegate method (such as tableView(_:itemsForBeginning:at:) or collectionView(_:itemsForBeginning:at:)), you create a UIDragItem from the NSUserActivity.

    That lets you create the drag item which you drag off to the side of the screen. The other half of the process is to handle the provided NSUserActivity in your UIWindowSceneDelegate. You use the data in the NSUserActivity to setup the newly created scene.