gpt4 book ai didi

iphone - 显示问题的MKA注释

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

我创建了MKMapView,上面有一个针脚。

按下图钉时,我会看到标题和副标题,但我想不点击就看到它。
因此,我希望标题和副标题在显示 map 后立即出现。

这是我的代码:

    self.mapView = [[[MKMapView alloc]init] autorelease];
mapView.frame = self.view.bounds;
mapView.delegate = self;
[self.view addSubview:mapView];

location = CLLocationCoordinate2DMake(lattitude, longitude);



MKCoordinateRegion region = self.mapView.region;
region.center = location;
region.span.longitudeDelta = kSpan;
region.span.latitudeDelta = kSpan;
[self.mapView setRegion:region animated:YES];

CustomMapAnnotation *newAnnotation = [[CustomMapAnnotation alloc] init];
newAnnotation.title = @"Title";
newAnnotation.subtitle = @"Subtitle";
newAnnotation.accessibilityTraits = UIAccessibilityTraitButton;

newAnnotation.coordinate = location;
annotation = newAnnotation;
[mapView addAnnotation:annotation];
[newAnnotation release];

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotationDel
{

MKPinAnnotationView *pinView = nil;

static NSString *defaultPinID = @"mapPin";

pinView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];

if (pinView == nil)
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotationDel reuseIdentifier:defaultPinID] autorelease];

pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
[pinView setSelected:YES];

UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(detailButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;

return pinView;

}

最佳答案

使用MKMapView's selectAnnotation:animated方法

[mapView selectAnnotation:YorAnnotation animated:YES];

有关更多信息,请阅读 How to trigger MKAnnotationView's callout view without touching the pin?How to Automatically Display Title/Subtitle on Map Annotation (pin)问题。

关于iphone - 显示问题的MKA注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15615201/

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