gpt4 book ai didi

ios - ios:mapKit viewForAnnotation从PIN消失弹出标题?

转载 作者:行者123 更新时间:2023-12-01 19:02:48 25 4
gpt4 key购买 nike

我正在尝试使用 MapKit 创建带有标题弹出窗口的可拖动的自定义图钉。但是当我实现 viewForAnnotation 使PIN显示为自定义图片时,其消失的弹出标题就好像我在 map 上插入PIN时一样,都不会显示titla弹出窗口,

如果我评论 viewForAnnotation 的话,它可以正常工作,但是当您点击图钉时,我希望两者都自定义图像和弹出标题。

下面是代码

- (void)viewDidLoad
{
MKCoordinateRegion newRegion = MKCoordinateRegionMakeWithDistance(LocCoordinate, 20000, 20000);
DDAnnotation *point = [[DDAnnotation alloc] init];
[point setCoordinate:mapCenter];
[point setTitle:@"Where am I"];
[point setSubtitle:@"I am here"];

[self.mvTripMap addAnnotation:point];
[self.mvTripMap setRegion:newRegion animated:YES];

[super viewDidLoad];
}

-(MKAnnotationView *)mapView:(MKMapView *)MapView viewForAnnotation:(id<MKAnnotation>)annotation{
static NSString *cabAnnotationIdentifier=@"cabAnnotationIdentifier";
MKAnnotationView *annotationView=[MapView dequeueReusableAnnotationViewWithIdentifier:cabAnnotationIdentifier];
if(!annotationView){
annotationView=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:cabAnnotationIdentifier];
annotationView.image=[UIImage imageNamed:@"start.png"];
annotationView.draggable = YES;
}
return annotationView;
}

DDAnnotation.h
#import <MapKit/MapKit.h>

@interface DDAnnotation : MKPlacemark {
CLLocationCoordinate2D coordinate_;
NSString *title_;
NSString *subtitle_;
}

// Re-declare MKAnnotation's readonly property 'coordinate' to readwrite.
@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate;

@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *subtitle;

@end

DDAnnotation.m
#import "DDAnnotation.h"

@implementation DDAnnotation

@synthesize coordinate = coordinate_;
@synthesize title = title_;
@synthesize subtitle = subtitle_;

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate addressDictionary:(NSDictionary *)addressDictionary {

if ((self = [super initWithCoordinate:coordinate addressDictionary:addressDictionary])) {
self.coordinate = coordinate;
}
return self;
}

@end

最佳答案

只需输入annotationView.canShowCallout= YES;即可使用

更新的代码

-(MKAnnotationView *)mapView:(MKMapView *)MapView viewForAnnotation:(id<MKAnnotation>)annotation{
static NSString *cabAnnotationIdentifier=@"cabAnnotationIdentifier";
MKAnnotationView *annotationView=[MapView dequeueReusableAnnotationViewWithIdentifier:cabAnnotationIdentifier];
if(!annotationView){
annotationView=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:cabAnnotationIdentifier];
annotationView.image=[UIImage imageNamed:@"start.png"];
annotationView.draggable = YES;
annotationView.canShowCallout= YES;
}
return annotationView;
}

关于ios - ios:mapKit viewForAnnotation从PIN消失弹出标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21755463/

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