-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Document how to avoid gesture recognizer conflicts #7816
Conversation
Adding Gesture info as discussed: mapbox#2278 (comment) Not sure if using codeblocks is kosher.
@note Adding your own gestures to MGLMapView will block the default gesture recognizer | ||
built into MGLMapView. If you would like to use your own, you will need to implement | ||
`gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:` in order to setup | ||
which gesture takes precedence. For example, you could create your own UITapGestureRecognizer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: surround MGLMapView
and UITapGestureRecognizer
in backticks.
@@ -75,6 +75,15 @@ typedef NS_ENUM(NSUInteger, MGLAnnotationVerticalAlignment) { | |||
|
|||
@note You are responsible for getting permission to use the map data and for | |||
ensuring that your use adheres to the relevant terms of use. | |||
@note Adding your own gestures to MGLMapView will block the default gesture recognizer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn’t need to be a @note
. Instead, place all this information above the existing @note
so that it doesn’t get lumped into it.
@@ -75,6 +75,15 @@ typedef NS_ENUM(NSUInteger, MGLAnnotationVerticalAlignment) { | |||
|
|||
@note You are responsible for getting permission to use the map data and for | |||
ensuring that your use adheres to the relevant terms of use. | |||
@note Adding your own gestures to MGLMapView will block the default gesture recognizer | |||
built into MGLMapView. If you would like to use your own, you will need to implement | |||
`gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:` in order to setup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qualify this method fully as -[UIGestureRecognizerDelegate gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]
. Eventually jazzy will autolink Apple APIs like this one: realm/jazzy#13.
@@ -75,6 +75,15 @@ typedef NS_ENUM(NSUInteger, MGLAnnotationVerticalAlignment) { | |||
|
|||
@note You are responsible for getting permission to use the map data and for | |||
ensuring that your use adheres to the relevant terms of use. | |||
@note Adding your own gestures to MGLMapView will block the default gesture recognizer | |||
built into MGLMapView. If you would like to use your own, you will need to implement | |||
`gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:` in order to setup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: replace “setup” (noun) with “set up” (verb phrase).
that will be called only if the default MGLMapView tap fails by implementing the following:<br/> | ||
```swift | ||
let mapTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(myCustomFunction)) | ||
mapView.gestureRecognizers?.forEach { if($0 is UITapGestureRecognizer){mapTapGestureRecognizer.require(toFail: $0)} } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A standard for
loop would be clearer than this call to forEach(_:)
, since this code isn’t using functional programming:
let mapTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(myCustomFunction))
for recognizer in mapView.gestureRecognizers! where recognizer is UITapGestureRecognizer {
mapTapGestureRecognizer.require(toFail: recognizer)
}
(Also, note that although gestureRecognizers
is optional, its documentation essentially eliminates the possibility of it being set to nil
.)
built into MGLMapView. If you would like to use your own, you will need to implement | ||
`gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:` in order to setup | ||
which gesture takes precedence. For example, you could create your own UITapGestureRecognizer | ||
that will be called only if the default MGLMapView tap fails by implementing the following:<br/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once you take this additional content out of @note
, this <br/>
will be unnecessary, and you can replace it with a blank line.
Yes, we’re using code blocks elsewhere too, since jazzy does a great job with it. Technically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`UITapGestureRecognizer` that will be called only if the default MGLMapView tap gesture fails by | ||
implementing the following: | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The swift
is still needed to let jazzy know to apply Swift syntax highlighting.
built into `MGLMapView`. If you would like to use your own, you will need to implement | ||
`-[UIGestureRecognizerDelegate gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]` | ||
in order to set up which gesture takes precedence. For example, you could create your own | ||
`UITapGestureRecognizer` that will be called only if the default MGLMapView tap gesture fails by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: missed an MGLMapView
.
Adding Gesture info as discussed: #2278 (comment)
Not sure if using codeblocks is kosher.