问题描述
- MKAnnotation显示问题
- 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];
时间: 2024-09-10 20:09:59