[英]Displaying custom UIView in callout of pin(annotation) in map, using MapKit
In my application i want to display custom view(with buttons) in the case of user touches annotation on map(standard pin). 在我的应用程序中,我希望在用户触摸地图上的注释(标准引脚)的情况下显示自定义视图(带按钮)。 i know that i can subclass MKAnnotationView and change the view of pin.
我知道我可以继承MKAnnotationView并更改pin的视图。 but how can i change the look of Additional information view, that appears when user touches pin(by default it displays title and subtitle of MKAnnotation object).
但是如何更改用户触摸图钉时显示的附加信息视图的外观(默认情况下显示MKAnnotation对象的标题和副标题)。 how can i do this?
我怎样才能做到这一点?
Thanks. 谢谢。
- (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];
}
Custom callout bubble can be displayed by making sub class of UIView Class. 可以通过创建UIView类的子类来显示自定义标注气泡。 You can check these links.
您可以查看这些链接。 http://blog.asynchrony.com/2010/09/building-custom-map-annotation-callouts-part-1/ http://blog.asynchrony.com/2010/09/building-custom-map-annotation-callouts-part-2/
http://blog.asynchrony.com/2010/09/building-custom-map-annotation-callouts-part-1/ http://blog.asynchrony.com/2010/09/building-custom-map-annotation-标注部分-2 /
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.