Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Document how to avoid gesture recognizer conflicts #7816

Merged
merged 5 commits into from
Jan 23, 2017

Conversation

nitrag
Copy link
Contributor

@nitrag nitrag commented Jan 23, 2017

Adding Gesture info as discussed: #2278 (comment)

Not sure if using codeblocks is kosher.

Adding Gesture info as discussed: mapbox#2278 (comment)

Not sure if using codeblocks is kosher.
@nitrag
Copy link
Contributor Author

nitrag commented Jan 23, 2017

@1ec5

@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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)} }
Copy link
Contributor

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/>
Copy link
Contributor

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.

@1ec5 1ec5 added this to the ios-v3.4.1 milestone Jan 23, 2017
@1ec5 1ec5 added documentation iOS Mapbox Maps SDK for iOS labels Jan 23, 2017
@1ec5
Copy link
Contributor

1ec5 commented Jan 23, 2017

Not sure if using codeblocks is kosher.

Yes, we’re using code blocks elsewhere too, since jazzy does a great job with it. Technically @pre would be more compatible with Quick Help, but Quick Help is quite broken for Objective-C and the backticks let us specify a syntax highlighting language.

Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! Here’s what it currently looks like, by the way:

MGLMapView

`UITapGestureRecognizer` that will be called only if the default MGLMapView tap gesture fails by
implementing the following:

```
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missed an MGLMapView.

@1ec5 1ec5 self-assigned this Jan 23, 2017
@1ec5 1ec5 added the macOS Mapbox Maps SDK for macOS label Jan 23, 2017
@1ec5 1ec5 changed the title Docs: Expound gesture implementation (iOS) Document how to avoid gesture recognizer conflicts Jan 23, 2017
@1ec5 1ec5 merged commit 0c95fcf into mapbox:release-ios-v3.4.0 Jan 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants