gpt4 book ai didi

iOS mapView - 只需轻轻一按即可拖动图钉

转载 作者:可可西里 更新时间:2023-11-01 06:10:25 25 4
gpt4 key购买 nike

我有一个带有两个图钉(自定义图钉)的 MapView。

两个引脚都设置为可拖动,但我的问题是在我可以拖动其中一个之前我必须先选择它才能开始拖动它。这意味着在屏幕上轻按两次。

我知道 this回答,但他的 map 上只有一个图钉,在我看来一次只能选择一个图钉,因此设置 [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;
}

最佳答案

通过添加 [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 - 只需轻轻一按即可拖动图钉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17318962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com