DidSelect Annotation getting called - ios

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.

Related

How can I detect longtap gesture on MapBox SDK for 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:].

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 Long Press Gesture Recognizer to Google Map in iOS

I added a GMSMapView to a UIScrollView and also i added Table View to that UIScrollView. No my task is if Long Press on any Location on the Map i will get that address and add that address to Table View and also i want to add a marker at that Location.
I write the Below code for adding long press gesture recognizer to the map but it is not working.
- (void)viewDidLoad
{
[super viewDidLoad];
self->map.delegate = self;
CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
UIScrollView *scroll=[[UIScrollView alloc] initWithFrame:fullScreenRect];
[self.view addSubview:scroll];
scroll.contentSize=CGSizeMake(320,1000);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:21.0000 longitude:78.0000 zoom:4.5];
map = [GMSMapView mapWithFrame:CGRectMake(0,0, self.view.frame.size.width,390) camera:camera];
[scroll addSubview:map];
UITableView *tab = [[UITableView alloc]initWithFrame:CGRectMake(0, 410, self.view.bounds.size.width, 300) style:UITableViewStylePlain];
[scroll addSubview:tab];
tab.delegate = self;
tab.dataSource = self;
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(mapLongPress:)];
longPressGesture.minimumPressDuration = 1.5;
[map addGestureRecognizer:longPressGesture];
}
-(void)mapLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
if(gestureRecognizer.state == UIGestureRecognizerStateBegan)
{
NSLog(#"%f",coordinate.latitude);
NSLog(#"%f",coordinate.longitude);
}
}
The Main Problem here is "mapLongPress" method is not called after i long press on the MapView.
Can any one Help me please.
You can use default MapVIew LongPress event
/**
* Called after a long-press gesture at a particular coordinate.
*
* #param mapView The map view that was pressed.
* #param coordinate The location that was pressed.
*/
- (void)mapView:(GMSMapView *)mapView
didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate;

Get Coordinates of view on which longpressGesture recogniser is added

I have added longpressGesture recognizer on view & given NoofTouchesRequired=2.I want to get the coordinates of both the views on which i have longpressed.
MyCode is as below:-
//---long press gesture---
UILongPressGestureRecognizer *longpressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector (handleLongpressGesture:)];
longpressGesture.minimumPressDuration = 4;
longpressGesture.numberOfTouchesRequired = 2;
[viewLongPress addGestureRecognizer:longpressGesture];
[longpressGesture release];
UIGestureRecognizer has a locationInView: method just for that.
-(void)handleLongpressGesture:(UIGestureRecognizer *)reco{
UIView *theSuperview = self.view;
CGPoint touchPointInSuperview = [reco locationInView:theSuperview];
}

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