iOS mapView - 只需轻轻一按即可拖动图钉
Posted
技术标签:
【中文标题】iOS mapView - 只需轻轻一按即可拖动图钉【英文标题】:iOS mapView - drag pin with only one tap 【发布时间】:2013-06-23 12:38:34 【问题描述】:我有一个 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;
【问题讨论】:
【参考方案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;
【讨论】:
以上是关于iOS mapView - 只需轻轻一按即可拖动图钉的主要内容,如果未能解决你的问题,请参考以下文章
来自 MapView Annotation-iOS 的缩略图