ios 6 - MKAnnotationView 中的问题

标签 ios iphone objective-c mkmapview mkannotationview

我正在创建 map 应用程序,我在 MKMap 上显示了 MKAnnotationView,我还没有为此创建任何子类,

我的 viewForAnnotation 委托(delegate)方法是:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKUserLocation class]])
    {
        return nil;
    }
    else if ([annotation isKindOfClass:[MKPointAnnotation class]])
    {
        static NSString * const identifier = @"MyCustomAnnotation";

        MKAnnotationView* annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

        if (annotationView)
        {
            annotationView.annotation = annotation;
        }
        else
        {
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
                                                          reuseIdentifier:identifier];

        }
        annotationView.canShowCallout = YES;
        annotationView.image = [UIImage imageNamed:@"pin"];
        UIImageView *imgview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50,50)];
        imgview.backgroundColor=[UIColor redColor];
        imgview.contentMode=UIViewContentModeScaleAspectFit;
        imgview.image=[UIImage imageNamed:@"bus"];
        imgview.backgroundColor=[UIColor clearColor];

        UIView *lftView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 50,50)];
        lftView.backgroundColor=[UIColor lightGrayColor];
        [lftView addSubview:imgview];

        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
        [rightButton setTitle:annotation.title forState:UIControlStateNormal];
        annotationView.rightCalloutAccessoryView = rightButton;
        annotationView.leftCalloutAccessoryView=lftView;
        annotationView.draggable = YES;
        annotationView.tag=101;
        return annotationView;
    }
    return nil;
}

我的输出在 iOS 7 中是完美的:

enter image description here

但在 iOS 6 中,leftCalloutAccessoryView 是从 annotaionview 出来的,它显示如下:

enter image description here

那么我该如何在 iOS 6 中解决这个问题呢?

最佳答案

关于 leftCalloutAccessoryView 的文档说:

The view to display on the left side of the standard callout bubble. The default value of this property is nil. The left callout view is typically used to display information about the annotation or to link to custom information provided by your application. The height of your view should be 32 pixels or less.

似乎是 iOS7 的标注会自动调整附件 View 的大小,但 iOS6 的标注不会。

尝试将硬编码的 CGRects 更改为 32px 高度。

关于ios 6 - MKAnnotationView 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22376762/

相关文章:

objective-c - 在 iOS 中处理 JSON 输出

ios - 发送消息动画像iMessage发送消息使用UICollectionView自定义

objective-c - 从任何地方以编程方式在 iOS 上截取屏幕截图

ios - CCAvenue“遇到错误。错误

ios - CALayer 上的绘制文本在运行时不显示或崩溃

ios - 使用 UIEdgeInsets 将 scrollView 定位在 NavController 下面并让它在 SWIFT 中滚动到后面

iphone - 使用 PHONEGAP 可达性 API 检测手机是否在线/离线

iphone - 如何在远程位置测试 iPhone 应用程序

ios - JSOG API 对象的 RestKit 映射

ios - 将圆角和边框设置为 ios7 中 UISearchBar 的背景(不是 UITextField)