ios - MKMapView 在注释选择 iOS8 上显示空白

标签 ios mkmapview ios8 xcode6 mkannotation

我在 iOS 8 中遇到了 MKMapview 的一些奇怪行为。 我有自定义 View (UIView 的子类),其中包含 MKMapview。

NMView -> MKMapView

NMView代码

#import "NMView.h"

@implementation NMView

@synthesize mapView;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        frame=self.bounds;
        self.translatesAutoresizingMaskIntoConstraints=NO;
        mapView=[[MKMapView alloc]initWithFrame:frame];
        mapView.showsUserLocation=YES;
        [mapView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
        [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
        mapView.delegate=self;
        [self addSubview:mapView];
        self.backgroundColor=[UIColor grayColor];
    }
    return self;
}
-(void)addCustomAnnotaion:(id<MKAnnotation>)annot{
  MKCoordinateRegion region=MKCoordinateRegionMake(annot.coordinate, MKCoordinateSpanMake(10.0f, 10.0f));
   [mapView setRegion:region];
    [mapView addAnnotation:annot];
   // [mapView selectAnnotation:annot animated:YES];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapViews viewForAnnotation:(id <MKAnnotation>)annotation
{

    if ([annotation isKindOfClass:[MKUserLocation class]]){
        return nil;
    }
    static NSString * const identifier = @"MyCustomAnnotation";
    MKAnnotationView* annotationView = (MKAnnotationView*)[mapViews dequeueReusableAnnotationViewWithIdentifier:identifier];

    if (annotationView){
        annotationView.annotation = annotation;
    }
    else{
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        annotationView.canShowCallout = YES;
        UIView *rightView=[[UIView alloc]initWithFrame:CGRectMake(5, 0, 80,50)];
        rightView.backgroundColor=[UIColor clearColor];

        UIButton* edit = [UIButton buttonWithType:UIButtonTypeCustom];
        [edit setImage:[UIImage imageNamed:@"editPOI"] forState:UIControlStateNormal];
        [edit addTarget:self action:@selector(editPoi:) forControlEvents:UIControlEventTouchUpInside];
        edit.backgroundColor=[UIColor clearColor];
        edit.frame=CGRectMake(15, 5, 30,30);

        UIButton* delButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [delButton setImage:[UIImage imageNamed:@"deletePOI"] forState:UIControlStateNormal];
        [delButton addTarget:self action:@selector(deletePoi:) forControlEvents:UIControlEventTouchUpInside];
        delButton.backgroundColor=[UIColor clearColor];
        delButton.frame=CGRectMake(55, 5, 30,30);

        [rightView addSubview:delButton];
        [rightView addSubview:edit];

        UIImageView *imgviewIcon=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
        [imgviewIcon setImage:[UIImage imageNamed:@"pin.png"]];
        [annotationView setImage:[UIImage imageNamed:@"pin.png"]];
        [annotationView layoutIfNeeded];
        annotationView.leftCalloutAccessoryView=imgviewIcon;
        annotationView.rightCalloutAccessoryView=rightView;

    }

    return annotationView;

}
-(IBAction)editPoi:(id)sender{
    //edit
}
-(IBAction)deletePoi:(id)sender{
    //delete
}

我正在将 NMView 添加到我的 View Controller

NMView *nv=[[NMView alloc]initWithFrame:CGRectMake(5, 5, 300, 400)];
[self.view addSubview:nv];

现在我使用 NMView 的自定义方法向 MapView 添加注释,

MKPointAnnotation *point=[[MKPointAnnotation alloc]init];
point.coordinate=pinCoordinate;
point.title=@"test";
[nv addCustomAnnotaion:point];

我已经在 iOS7 中测试过它工作正常:

enter image description here

但是在iOS8中,选择注释时整个NMView变为空白

这是 iOS 8 的错误还是我做错了什么? 请帮忙..

编辑

如果我以编程方式选择注释,那么 iOS 8 中也会出现同样的问题。

[mapView selectAnnotation:annotanimate:YES];

其他人也面临这个问题吗?

iOS8 黑屏。 : enter image description here

我已在以下网址上传项目: https://drive.google.com/file/d/0BxkVP7smm8Z6SnM1UjBxcjc5aDg/view?usp=sharing

请检查并告诉我..

最佳答案

我不太清楚为什么,但如果你删除这一行,它就会起作用:

self.translatesAutoresizingMaskIntoConstraints=NO;

引用: Views disappear when `translatesAutoresizingMaskIntoConstraints` set `NO`

关于ios - MKMapView 在注释选择 iOS8 上显示空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26175061/

相关文章:

iphone - 将文本设置为自定义表格单元格标签时崩溃

ios - 如何检查解析 Xcode 中获取的用户名

javascript - 从 JSContext 中的 JS Promise/async 函数获取值

java - 将基于 Java OpenGL 的 Android 游戏移植到 iOS(无 native 代码)

iphone - 删除现有注释并将新注释添加到 map View 中

iphone - UIPopoverController 在没有委托(delegate)调用的情况下解散

ios - MKAnnotation 捏住 map 时旋转

ios - 无法发现外围蓝牙低功耗设备

ios - 在 Swift 中每 30 分钟发送一次位置更新

ios - AutoLayout 限制 View 位于键盘正上方