MKMapView 中有一個標志針
點擊標記針時可以看見標題和副標題,怎麼樣不需要點擊標記讓標題自動顯示。
代碼如下:
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
的selectAnnotation:animated
方法
[mapView selectAnnotation:YorAnnotation animated:YES];