gpt4 book ai didi

ios 6 - MKAnnotationView 中的问题

转载 作者:行者123 更新时间:2023-11-29 03:09:31 28 4
gpt4 key购买 nike

我正在创建 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com