Long Press Gesture in ArcGis Map in IOS - ios

I'm working with ArcGis Map in my ios app. I'm trying to apply a long press gesture on it. But i'm getting an error Value of type 'BCBaseMapView?' has no member 'addGestureRecognizer' . How i can add long gesture on it. This is what i coded in it.
let lpgr = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress))
lpgr.minimumPressDuration = 0.5
lpgr.delaysTouchesBegan = true
// lpgr.delegate = self
self.mapView.addGestureRecognizer(lpgr)
#objc func handleLongPress(sender: UILongPressGestureRecognizer)
{
print("longpressed")
self.addWaypointOnMap()
}
This is my code i'm getting error on this line.
self.mapView.addGestureRecognizer(lpgr)
This is my mapView
var mapView: BCBaseMapView?

If the superview of BCBaseMapView is MKMapView then try to add it on super view using:
self.mapView.super.addGestureRecognizer(lpgr)
OR
self.mapView.superview.addGestureRecognizer(lpgr)

Related

UITapGestureRecognizer not picking up inputs on tvOS

I'm working on a small SpriteKit game for tvOS. I need to receive input when the user clicks the play/pause button on the remote. Looking at the docs, it appears that I should just have to add a UITapGestureRecognizer to my scene's view. I implemented the following code:
override func didMove(to view: SKView) {
let tapPlayPause = UITapGestureRecognizer(target: self, action: #selector(tapTesting))
tapPlayPause.allowedPressTypes = [NSNumber(value: UIPress.PressType.playPause.rawValue)]
view.addGestureRecognizer(tapPlayPause)
let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(swipeUp))
swipeUp.direction = .up
view.addGestureRecognizer(swipeUp)
}
#objc func tapTesting(_ sender: UITapGestureRecognizer) {
print("TAP")
}
However, when I run the app on my Apple TV 4K (running tvOS 15), there is no output and from what I can tell no tap code is getting triggered.
I have tried the code with self.isUserInteractionEnabled = true as well but I still do not receive tap inputs.
The swipe gesture I implemented above works perfectly thought, and the tap gesture works on my iOS devices. Does anyone have any idea as to why this is the case?
Thanks!
For tvOS gestures, you also need to set allowedTouchTypes to .indirect
tapPlayPause.allowedTouchTypes = [NSNumber(touchType: .indirect)]

Mapbox iOS double tap handling

I'm using Mapbox iOS SDK, making the next layout: mapView and two buttons ("zoom in" and "zoom out").
I can't figure out how to correctly handle double tap on buttons.
Double tap on "zoom out" button zooms me in - as far as I understand, Mapbox's mapView intercept and handle my double tap.
I've tried the following code in viewDidLoad:
let doubleTap = UITapGestureRecognizer(target: self, action: #selector(handleDoubleTap))
doubleTap.numberOfTapsRequired = 2
zoomOutButton.addGestureRecognizer(doubleTap)
let singleTap = UITapGestureRecognizer(target: self, action: #selector(handleSingleTap))
singleTap.numberOfTapsRequired = 1
singleTap.require(toFail: doubleTap)
zoomOutButton.addGestureRecognizer(singleTap)
and handlers (just to see it works):
func handleSingleTap(tap: UITapGestureRecognizer) {
print("single")
}
func handleDoubleTap(tap: UITapGestureRecognizer) {
print("double")
}
It doesn't work. How can I handle double tap on "zoom out" button to zoom out twice?

Add single, double and triple tap gestures to all "buttons" in custom keyboard in swift

I'm trying to create a keyboard the allows single tap, double tap, and triple tap. So I want to add a UITapGestureRecognizer() to each button in my keyboard. I know how to do this manually from the xib file (add each letter it's own gesture, which would take ages) but not quite sure how to do it in the Controller.
I wrote this for double tap in the viewDidLoad() method:
let doubleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "doubleTapCharacter:")
doubleTap.numberOfTapsRequired = 2
for button in self.view.subviews{
button.addGestureRecognizer(doubleTap)
}
and created a doubleTapCharacter() method but it's still not working. I also want to be able to send information to the doubleTapCharacter method.
Any help would be much appreciated. Also, I'm very new to swift so if the instructions are complicated, I'd highly appreciate it if you can break it down a little.
create and add the gesture recognizers:
for button in view.subviews {
// create the gesture recognizer
let doubleTapRecognizer = UITapGestureRecognizer(target: self, action: "doubleTapCharacter:")
doubleTapRecognizer.numberOfTapsRequired = 2
// add gesture recognizer to button
button.addGestureRecognizer(doubleTapRecognizer)
}
then implement the target method:
func doubleTapCharacter(doubleTapRecognizer: UITapGestureRecognizer) {
let tappedButton = doubleTapRecognizer.view as! UIButton
print(tappedButton.titleForState(UIControlState.Normal))
}

UITapGestureRecognizer is not working with Google Maps SDK

I have a mapViewController with some custom UIView over it (just two labels with some background). I want to show new ViewController after the tap on this UIView.
So, my code (this was a working solution for other cases) for custom UIView:
tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "checkGesture:")
tapGestureRecognizer.numberOfTapsRequired = 1
self.userInteractionEnabled = true
self.addGestureRecognizer(tapGestureRecognizer)
and
func checkGesture(sender: UITapGestureRecognizer) {
print("it works")
}
Could anyone please tell me what is the problem here?
Edit (Solved): So, I tried to put this custom UIView on another ViewController and it works. It seems that main source of this problem is the next part of code in my MapViewController:
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera:camera)
self.view = mapView
Without the last line (self.view = mapView), my custom UIView works (but I don't have any map, so I had to change this code slightly).
let mapView = GMSMapView.mapWithFrame(CGRectMake(0, 0, self.view.frame.width, self.view.frame.height), camera:camera)
self.view.addSubview(mapView)
I think that best solution if you don't want to add the GMSMapView as a subview is:
Add GMSMapViewDelegate to your ViewController.
On viewDidLoad of your ViewController add myMapView.delegate = self.
Also add the following function:
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
print("!map tapped!")
}
I don't know if it is the problem, but change this line
tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "checkGesture:")
to this
tapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("checkGesture:"))
and report me if its working, or if there are further problems

PointAnnotation callout on MKMapView appears and then immidiately disappears

I am creating a simple point annotation with a callout inside the UITapGestureRecognizer delegate.
The first time I tap on the map, the pin appears with the callout but the callout immediately disappears after that.
The second time I tap on the same pin, the callout appears and stays there, not sure why it disappears at the first time.
#IBAction func handleMapTouch(recognizer: UITapGestureRecognizer){
let view = recognizer.view
let touchPoint=recognizer.locationInView(view)
var touchCord=CLLocationCoordinate2D()
touchCord = mapView.convertPoint(touchPoint, toCoordinateFromView:
mapView)
mapView.removeAnnotations(mapView.annotations)
pointAnnotation.coordinate=touchCord
pointAnnotation.title="ABC"
pointAnnotation.subtitle="DEF"
mapView.addAnnotation(pointAnnotation)
mapView.selectAnnotation(pointAnnotation, animated: true)
}
Just in case someone else has the same problem, although Keith's answer works, in my case it disrupts other gestures associated to the map, like pinch and zoom.
For me, delaying some milliseconds the action of showing the callout worked better.
In Swift 3:
let deadlineTime = DispatchTime.now() + .milliseconds(500)
DispatchQueue.main.asyncAfter(deadline: deadlineTime) {
mapView.addAnnotation(pointAnnotation)
mapView.selectAnnotation(pointAnnotation, animated: true)
}
I have the same problem. I don't know how to solve it, either, but I found a workaround. Maybe it can help you too.
I used LongPressGesture to replace TapGesture
In Viewdidload:
let longPress = UILongPressGestureRecognizer(target: self, action: "addAnnotation:")
longPress.minimumPressDuration = 0.1
self.mapView.addGestureRecognizer(longPress)
In function addAnnotation:
if(gestureRecognizer.state == .Ended){
self.mapView.removeGestureRecognizer(gestureRecognizer)
//remove all annotation on the map
self.mapView.removeAnnotations(self.mapView.annotations)
//convert point user tapped to coorinate
let touchPoint: CGPoint! = gestureRecognizer.locationInView(self.mapView)
let touchMapCoordinate: CLLocationCoordinate2D = self.mapView.convertPoint(touchPoint, toCoordinateFromView: self.mapView)
showCustomAnnotation(touchMapCoordinate)
}
self.mapView.addGestureRecognizer(gestureRecognizer)

Resources