在mapview上添加叠加层时,iOS应用会变得无法响应

时间:2016-10-12 07:45:37

标签: ios objective-c mkmapview ios10 mkoverlay

我正在使用MKPolygon在MKMapView上绘制叠加层。它在iOS 9中运行良好,在将Xcode和iOS更新到Xcode 8和iOS 10之后,它无法工作并使应用程序无响应 Overley计数是90.这有问题吗? 在这里我的代码,看看

    - (void)addOverlaysOnMap
{
    NSMutableArray<MKPolygon *> *array = [NSMutableArray new];

  //here arrRegions is NSMutableArray has json data in model form 
    for (int i = 0; i < arrRegions.count; i++) {

        RegionModel *rModel = arrRegions[i];

        [array addObject:[self getPolygon:rModel]];

    }

    for (int i = 0; i < array.count; i++) {
        MKPolygon *poly = array[i];
        [regionMapView addOverlay:poly];

    }


 -(MKPolygon *)getPolygon:(RegionModel *)rModel{
    NSLog(@"%@",rModel.coordinates);

    if (rModel.coordinates == nil) {
        rModel.coordinates = @"";
    }

    NSArray *arrCoordinates = [rModel.coordinates componentsSeparatedByString:@";"];


    if (arrCoordinates.count > 0) {


        CLLocationCoordinate2D coordinates[arrCoordinates.count];
        int index = 0;
        for (NSString *strCoordinate in arrCoordinates) {

            NSArray *coordinate = [strCoordinate componentsSeparatedByString:@","];

            coordinates[index] = CLLocationCoordinate2DMake([coordinate.firstObject doubleValue], [coordinate.lastObject doubleValue]);

            index++;
        }

      MKPolygon *polygon = [MKPolygon polygonWithCoordinates:coordinates count:arrCoordinates.count];

        if (rModel.stateid == 0) {
            NSLog(@"no stateID");
        }

        polygon.accessibilityHint = [NSString stringWithFormat:@"%0.f,%0.f, %@",rModel.regionid,rModel.stateid, rModel.regionname];


        return polygon;
    }else{
        return nil;
    }

}

这是我的MKOverlay代表

-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {

    MKPolygonRenderer *render = [[MKPolygonRenderer alloc]initWithOverlay:overlay];
    render.lineWidth = 2;

    render.strokeColor = [UIColor colorWithRed:0.0f/255.0f green:195.0f/255.0f blue:79.0f/255.0f alpha:1.0f];

return render;

    }

请帮我弄清楚问题是什么以及如何解决。

0 个答案:

没有答案