我有一个带有两个引脚的MapView(自定义引脚)。
两个引脚都设置为可拖动,但我的问题是在我可以拖动其中一个之前我首先必须先选择它才能开始拖动它。这意味着屏幕上有两个水龙头。
我知道this回答,但他的地图上只有一个引脚,在我看来,一次只能选择一个引脚,所以设置[MyPin setSelected:YES];在这种情况下,我不会帮助我。
感谢您的帮助!
//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;
}
答案 0 :(得分:1)
通过添加[MyPin setSelected:YES]来管理解决我自己的问题;在这样的if语句中:
//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;
}