IOS mapView - drag a pin with one touch

I have a MapView with two contacts on it (user contacts).

Both pins are set to drag and drop, but the problem is that before I can drag one of them, I first need to select it before I can drag it. This means two taps on the screen.

I know about this answer, but it has only one output on the map, and it seems to me that only one output at a time can be selected to set [MyPin setSelected: YES]; would not help me in this case.

Thanks for the help!

//Custom pin on mapview -(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { MKAnnotationView *MyPin=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"]; MyPin.draggable = YES; //Get annotaion title to determine what image to use MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc]init]; annotationPoint = annotation; if([annotationPoint.title isEqualToString:@"user"]) { MyPin.image = [UIImage imageNamed:@"userLocation_pin"]; MyPin.centerOffset = CGPointMake(-13, -5); //Offset custom image to display at the exact pin point GPointMake([left/right], [up/down]); } else if ([annotationPoint.title isEqualToString:@"destination"]) { MyPin.image = [UIImage imageNamed:@"destination_pin_up"]; MyPin.centerOffset = CGPointMake(-13, -5); //Offset custom image to display at the exact pin point GPointMake([left/right], [up/down]); } return MyPin; } 
+4
source share
1 answer

I managed to solve my own problem by adding [MyPin setSelected: YES]; inside if statements, such as:

 //Custom pin on mapview -(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { MKAnnotationView *MyPin=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"]; MyPin.draggable = YES; //Get annotaion title to determine what image to use MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc]init]; annotationPoint = annotation; if([annotationPoint.title isEqualToString:@"user"]) { MyPin.image = [UIImage imageNamed:@"userLocation_pin"]; MyPin.centerOffset = CGPointMake(-13, -5); //Offset custom image to display at the exact pin point GPointMake([left/right], [up/down]); [MyPin setSelected:YES]; } else if ([annotationPoint.title isEqualToString:@"destination"]) { MyPin.image = [UIImage imageNamed:@"destination_pin_up"]; MyPin.centerOffset = CGPointMake(-13, -5); //Offset custom image to display at the exact pin point GPointMake([left/right], [up/down]); [MyPin setSelected:YES]; } return MyPin; } 
+1
source

Source: https://habr.com/ru/post/1488268/


All Articles