How can I detect longtap gesture on MapBox SDK for IOS? - ios

How can i detect longtap gesture on MapBox SDK for IOS?
I try below code.
but mapLongTap are never called.
-(void)mapInit
{
RMMBTilesSource *offlineSource = [[RMMBTilesSource alloc] initWithTileSetResource:#"tokyo5" ofType:#"mbtiles"];
mapView = [[RMMapView alloc] initWithFrame:_mapBaseView.bounds andTilesource:offlineSource];
mapView.zoom = 0;
mapView.delegate = self;
mapView.missingTilesDepth = 5;
mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
mapView.adjustTilesForRetinaDisplay = YES;
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:#selector(mapLongTap:)];
[longPressGesture setMinimumPressDuration:1.0];
// [_mapBaseView addGestureRecognizer:longPressGesture];
[mapView addGestureRecognizer:longPressGesture];
[self.mapBaseView addSubview:mapView];
}
-(void)mapLongTap:(UISwipeGestureRecognizer *)gesture
{
NSLog(#"LongTap");
}

RMMapView already has a long press gesture recognizer. See -[RMMapViewDelegate longPressOnMap:at:].

Related

Add Gesture to UIImagePickerController cameraOverlayView

I have a customed overlay view for my UIImagePickerController.
I want to add an UITapGestureRecognizer in this overlay view in order to draw a circle and focus the camera.
But once I added the gesture, my method is never called and I don't understand why.
Here is my code:
// Overlay view
UIView *overlay = [[UIView alloc] initWithFrame:self.view.frame];
// TapGesture
UITapGestureRecognizer *stabilisateurGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(Stabiliser:)];
stabilisateurGesture.numberOfTapsRequired = 1;
[overlay addGestureRecognizer:stabilisateurGesture];
// UIImagePickerController
pickerCamera = [[UIImagePickerController alloc] init];
pickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerCamera.delegate = self;
pickerCamera.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
pickerCamera.modalPresentationStyle = UIModalPresentationFullScreen;
pickerCamera.showsCameraControls = NO;
pickerCamera.cameraOverlayView = overlay;
And here the gesture method:
- (void)Stabiliser:(UITapGestureRecognizer *)gesture {
CGPoint point = [gesture locationInView:gesture.view];
// Create circle
UIView *cercleRouge = [[UIView alloc] initWithFrame:CGRectMake(point.x-(86/2), point.y-(86/2), 86, 86)];
cercleRouge.layer.borderColor = [[UIColor redColor] CGColor];
cercleRouge.layer.borderWidth = 4;
cercleRouge.layer.cornerRadius = cercleRouge.frame.size.height/2;
[gesture.view addSubview:cercleRouge];
}
Thank you in advance.

how to access subview control in UITapGesture in objective- c?

Hello Friends Please help me,
I have added UITapGesture on UIWindow but i can't able access parent control in screen
UIRotationGestureRecognizer *rot =[[UIRotationGestureRecognizer alloc] initWithTarget:self action:#selector(handleRotation:)];
rot.cancelsTouchesInView = NO;
rot.delegate = self;
UIPinchGestureRecognizer *pinch =[[UIPinchGestureRecognizer alloc] initWithTarget:self
action:#selector(handlePinch:)];
pinch.cancelsTouchesInView = NO;
pinch.delegate = self;
/* UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self
action:#selector(handlePan:)];
pan.cancelsTouchesInView = NO;
pan.delegate = self;*/
//circle gesture
gr = [[MDCircleGestureRecognizer alloc] init];
[gr addTarget:self action:#selector(handleGesture:)];
//[self.view addGestureRecognizer:gr];
//gr.delegate = (id<MDCircleGestureFailureDelegate>)self.view;
gr.delegate = self;
gr.cancelsTouchesInView = NO;
////Z gesture
cg = [[CharGesture alloc] initWithTarget:self action:#selector(zLetterMade:)];
cg.delegate=self;
cg.cancelsTouchesInView = NO;
//Add on window - RR
[[[UIApplication sharedApplication]delegate]window].gestureRecognizers = #[gr,cg,pinch,rot];
please confirm that you have given UIGestureRecognizerDelegate and enable interaction [[[UIApplication sharedApplication]delegate]window].userInteractionEnabled=YES;

DidSelect Annotation getting called

I have a tap gesture recognizer added to a mapView. My MapView has annotations and when I tap on an annotation only dismissCollectionView is called. DidSelectAnnotation method not getting called. How do I stop tapgesture method(dismisscollection) calling when I tap on an annotation? Any help will be appreciated.
self.m_mapView = [[MKMapView alloc] init];
self.m_mapView.frame = CGRectMake(0, 0, 320, 568);
self.m_mapView.delegate = self;
// MapHeight = self.m_mapView.frameHeight;
m_locationManager = [[CLLocationManager alloc] init];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0")) {
[m_locationManager requestWhenInUseAuthorization];
[m_locationManager requestAlwaysAuthorization];
}
self.m_mapView.mapType = MKMapTypeStandard;
[self.m_mapView setUserTrackingMode:MKUserTrackingModeFollow];
[self.m_bgImageView addSubview:self.m_mapView];
m_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
m_locationManager.delegate = self;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(dismissCollectionView)];
tapGesture.numberOfTouchesRequired = 1;
tapGesture.cancelsTouchesInView = NO;
[self.m_mapView addGestureRecognizer:tapGesture];
If you want both actions to happen: Set the delegate of your gesture recognizer and implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: to return YES for your recognizer and any that the map view uses internally.
If you want dismissCollectionView and mapView:didSelectAnnotationView: to be mutually exclusive: Implement -gestureRecognizer:shouldReceiveTouch: and check if the touch location is in an MKAnnotationView or one of its subviews. Only return YES if the location is outside all annotation views.

iOS: The second UITapGestureRecognizer I add does not work

I have 2 UIPickerViews as InputViews for textfields. I want to detect tap events on both of them. But only the taps on the first are detected.
Here is my code in ViewDidLoad:
// for Behandler selection
_behandlerArray = [self fetchBehandler];
_behandlerPickerView = [[UIPickerView alloc] init];
_behandlerTextField.inputView = _behandlerPickerView;
_behandlerPickerView.dataSource = self;
_behandlerPickerView.delegate = self;
[_behandlerPickerView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(behandlerPickerTapped:)]];
// for Medikamente selection
_medikamenteArray = [self fetchMedikamente];
_medikamentePickerView = [[UIPickerView alloc] init];
_medikamenteTextField.inputView = _medikamentePickerView;
_medikamentePickerView.dataSource = self;
_medikamentePickerView.delegate = self;
[_medikamentePickerView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(medikamentePickerTapped:)]];
And here are the methods:
-(void)behandlerPickerTapped:(UIGestureRecognizer *)gestureRecognizer{
NSLog(#"_behandlerPickerView tapped");
}
-(void)medikamentePickerTapped:(UIGestureRecognizer *)gestureRecognizer{
NSLog(#"_medikamentePickerView tapped");
}
But only the taps on _behandlerPickerView are detected/logged.
Can I only added one UITapGestureRecognizer?
And if so, how do I know in the method, which view was tapped?

Adding Tap GestureRecognizer to MKOverlay

I am trying to get overlays on my map to responds to touches. Hence, I wanted to add a UIGestureRecognizer for taps to the MKOverlayView that is created in the method mapView:viewForOverlay.
I added the following code in this method:
if ([overlay isKindOfClass:[MKPolygon class]])
{
MKPolygonView* aView = [[MKPolygonView alloc] initWithPolygon:(MKPolygon*)overlay];
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
tap.delegate = self;
aView.fillColor = color;
aView.strokeColor = color;
aView.lineWidth = 2;
[aView addGestureRecognizer:tap];
return aView;
}
In addition, I conform to the UIGestureRecognizerDelegate - Protocol and I implemented the method handleGesture:. So far this method is never called.
Any ideas what I am doing wrong?
Thanks!

Resources