长按注释时,注释图像会被 RedPushPin 替换
我创建了自定义注释,如下所示:
-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
MKPinAnnotationView *view = nil;
if (annotation != mapView.userLocation)
{
view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotationIdentifier"];
if (!view)
view = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"myAnnotationIdentifier"];
if (((CustomAnnotation *)annotation).annotationType == 1)
{
view.image = [UIImage imageNamed:@"type1.png"];
view.rightCalloutAccessoryView = nil;
view.canShowCallout = YES;
}
else
{
view.image = [UIImage imageNamed:@"type2.png"];
view.rightCalloutAccessoryView = nil;
view.canShowCallout = YES;
}
}
return view;
}
问题:当用户在任何注释图像(类型 1 或类型 2)上按住 2 秒时,图像将被红色 PushPin 替换(iPhone MKPinAnnotationView 的默认值)。
我想避免这种替换。我怎样才能这样做呢?
I have created Custom Annotation with following:
-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
MKPinAnnotationView *view = nil;
if (annotation != mapView.userLocation)
{
view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotationIdentifier"];
if (!view)
view = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"myAnnotationIdentifier"];
if (((CustomAnnotation *)annotation).annotationType == 1)
{
view.image = [UIImage imageNamed:@"type1.png"];
view.rightCalloutAccessoryView = nil;
view.canShowCallout = YES;
}
else
{
view.image = [UIImage imageNamed:@"type2.png"];
view.rightCalloutAccessoryView = nil;
view.canShowCallout = YES;
}
}
return view;
}
Problem: When User press and hold for 2 seconds on any Annotation Image (type1 or type2), Image gets replaced by Red PushPin(Default for iPhone MKPinAnnotationView).
I want to avoid this replacement. How can I do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要声明和创建
MKPinAnnotationView
,而是声明并创建一个普通的MKAnnotationView
。MKPinAnnotationView
喜欢默认使用红色图钉,这就是它的用途。Instead of declaring and creating an
MKPinAnnotationView
, declare and create a plainMKAnnotationView
.The
MKPinAnnotationView
likes to default to the red pin which is what it's for.使用
didDeselectAnnotationView
和didSelectAnnotationView
并重新选择图像,如下所示:-Use
didDeselectAnnotationView
anddidSelectAnnotationView
and reselect the image as you did by :-