Iphone 使用MapKit在地图中的接点(注释)标注中显示自定义UIView
在我的应用程序中,如果用户触摸地图上的注释(标准pin),我希望显示自定义视图(带按钮)。 我知道我可以子类MKAnnotationView并更改pin的视图。但如何更改附加信息视图的外观,即当用户触摸pin时显示的视图(默认情况下,它显示MKAnnotation对象的标题和副标题)。 我该怎么做Iphone 使用MapKit在地图中的接点(注释)标注中显示自定义UIView,iphone,map,mkmapview,Iphone,Map,Mkmapview,在我的应用程序中,如果用户触摸地图上的注释(标准pin),我希望显示自定义视图(带按钮)。 我知道我可以子类MKAnnotationView并更改pin的视图。但如何更改附加信息视图的外观,即当用户触摸pin时显示的视图(默认情况下,它显示MKAnnotation对象的标题和副标题)。 我该怎么做 谢谢。通过创建UIView类的子类,可以显示自定义标注气泡。 - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id )
谢谢。通过创建UIView类的子类,可以显示自定义标注气泡。
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id )annotation
{
MKPinAnnotationView *pinView = nil;
static NSString *defaultPinID = @"ReusedPin";
pinView = (MKPinAnnotationView*)[mVdequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
if (((PinAnnotationView*)annotation).tag == 0 )
{
pinView.pinColor = MKPinAnnotationColorPurple;
}
else {
pinView.pinColor = MKPinAnnotationColorRed;
}
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
UIImageView *pinImageView = [[UIImageView alloc] initWithFrame:CGRectMake(-5, 0, 34, 34)];
UIImage *pinImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon" ofType:@"png"]];
pinImageView.image = pinImage;
[pinImage release];
[pinView addSubview:pinImageView];
[pinImageView release];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
btn.tag = ((PinAnnotationView*)annotation).tag;
pinView.rightCalloutAccessoryView = btn;
return pinView;
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
if ( control.tag !=0) {
ShowProviderDetailVC *viewControlle = [[ShowProviderDetailVC alloc]initWithNibName:@"ShowProviderDetailVC" bundle:nil];
viewControlle.lastViewName = @"SearchView";
for (NSMutableDictionary* dict in globalLocArray) {
if ( control.tag ==[[dict valueForKey:@"ID"] intValue] )
{
viewControlle.providerInfoDict = dict;
}
}
[self.navigationController pushViewController:viewControlle animated:YES];
[viewControlle release];
}
你可以查看这些链接。
哦,谢谢你。我是新手,我甚至不知道RightCallout附件按钮。