UIGestureRecognizer locationInView: behaves unexpectedly for UILongPressGestureRecognizer

Originator:matej
Number:rdar://29733121 Date Originated:19-Dec-2016 02:21 PM
Status:Open Resolved:
Product:iOS Product Version:10.2
Classification:Other Bug Reproducible:Always
 
Summary:

The `locationInView:` method in its documentation specifies that passing in `nil` as the view parameter results the returned point being in the window's coordinate system. 

> A UIView object on which the gesture took place. Specify nil to indicate the window.

and

> If nil is specified for view, the method returns the gesture location in the window’s base coordinate system.

This is true for some gesture recognizers (e.g., `UIPanGestureRecognizer`), but not for others (e.g., `UILongPressGestureRecognizer`). For `UILongPressGestureRecognizer` the returned point when passing in `nil` will be in the screen's coordinate system. 

Steps to Reproduce:

Open the attached project. Follow the on screen instructions. Inspect the code when the assertion triggers for the long press gesture recognizer. 

Expected Results:

locationInView:nil would always return the location in the window’s coordinate system

Actual Results:

locationInView:nil returns the location in the screen’s coordinate system for UILongPressGestureRecognizer

Regression:

Tested on iOS 10.2 and 9.3. The behavior is the same. 

Notes:

The documentation mentions that the behavior of this method may differ between `UIGestureRecognizer` subclasses. 

> For objects of the UISwipeGestureRecognizer and UITapGestureRecognizer classes, the location returned by this method has a significance special to the gesture. This significance is documented in the reference for those classes.

However in contrast to `UISwipeGestureRecognizer.h`, `UILongPressGestureRecognizer.h` doesn't say anything about how that method behaves. I would like to request that either this behavior is unified (my preferred resolution), or that the documentation is updated accordingly.

Comments

Sample

https://github.com/PSPDFKit-labs/radar.apple.com/tree/master/29733121%20-%20LocationInViewSample


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!