UIViewControllerPreviewingDelegate Cancellation Callback

Originator:rileytestut
Number:rdar://27496672 Date Originated:7/22/16
Status:Open Resolved:
Product:iOS SDK Product Version:iOS 10
Classification:Enhancement Reproducible:n/a
 
Summary:
Sometimes when presenting a UIViewController with peek/pop, it is important to know if the user cancelled the transition. As an example, if the presented UIVC plays media when visible, it makes sense to start playing when peek begins, but stop playing if the user cancels the transition. Unfortunately, there is no way to know if the user did in fact cancel the transition.

Steps to Reproduce:
1. Return a UIVC via UIViewControllerPreviewingDelegate's previewingContext(_:viewControllerForLocation:) callback.
2. Cancel the peek/pop

Expected Results:
There is a UIViewControllerPreviewingDelegate callback to let you know when the user cancels the transition.

Actual Results:
There is no such transition.

Version:
iOS 10

Notes:
There are three possible ways to (potentially) accomplish this, unfortunately all three have limitations.

• If the UIVC is ephemeral, media can be stopped in deinit. However, if the UIVC is still retained after being cancelled (e.g. it is expensive to create so it is reused for performance reasons), this method cannot be used.

• You can use UIPreviewInteraction and it's associated delegate methods to determine when the user cancels alongside the normal peek/pop, but unfortunately presenting the UIPreviewActions will cause it to call the cancel callback, and no further delegate methods will be called.

• You could try to use the UIVC lifecycle methods, but view(Will/Did)Disappear is called for both user cancelling *and* committing the pop transition, and it is impossible from the limited callbacks to know which it is.

Configuration:
iPhone 6s

Attachments:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!