我创建了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/