gpt4 book ai didi

iphone - MKMapView 加载时覆盖除 View 之外的所有内容?仅限iOS5<

转载 作者:行者123 更新时间:2023-11-29 04:13:14 25 4
gpt4 key购买 nike

出于某种原因,我的 MKMapView 有时会覆盖覆盖除加载时 View 之外的所有内容。您可以在 View 加载后滚动到一侧并查看叠加层。另外,该问题仅在ios5及以下版本中存在,在ios6中不会出现该问题。我发现,如果放大或缩小 map , map 的覆盖部分将调整为新 View 。例如,如果您缩小,则 map 的非重叠部分将调整并变大以适应 View 的新尺寸,但如果您向侧面滚动,则 map 仍然以 viewForOverlay 中定义的颜色全部重叠方法。我不知道为什么,已经研究了一段时间了,谷歌没有发现任何东西。这是我的一些代码:

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {

if([overlay class] == [MKPolyline class]){
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];

int lineSize = [self.ud integerForKey:@"lineSize"];
polylineView.lineWidth = lineSize;

NSString *lineColor = [self.ud objectForKey:@"lineColor"];

if([lineColor isEqualToString:@"Red"]){
polylineView.strokeColor = [UIColor redColor];
}else if([lineColor isEqualToString:@"Blue"]){
polylineView.strokeColor = [UIColor blueColor];
}else if ([lineColor isEqualToString:@"Orange"]){
polylineView.strokeColor = [UIColor orangeColor];
}else if([lineColor isEqualToString:@"Green"]){
polylineView.strokeColor = [UIColor greenColor];
}else if([lineColor isEqualToString:@"Black"]){
polylineView.strokeColor = [UIColor blackColor];
}
return polylineView;
}else{
MKOverlayView *overlayToReturn = [[MKOverlayView alloc]initWithOverlay:overlay];
return overlayToReturn;
}
}

这就是我得到的:

MKMapView

最佳答案

我怀疑问题出在您创建 MKPolyline 或 lineSize 设置上。此代码在这里运行良好:

#import <MapKit/MapKit.h>
#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
MKMapView *map = [[MKMapView alloc] initWithFrame:self.view.bounds];
map.delegate = self;
[self.view addSubview:map];

CLLocationCoordinate2D coords[] = { {42,-83}, {32, -84}, {45,-78}, {42,-83} };
MKPolyline *overlay = [MKPolyline polylineWithCoordinates:coords count:4];
[map addOverlay:overlay];
}

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {

if([overlay class] == [MKPolyline class]){
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];

int lineSize = 2; //[self.ud integerForKey:@"lineSize"];
polylineView.lineWidth = lineSize;

NSString *lineColor = @"Red"; // [self.ud objectForKey:@"lineColor"];

if([lineColor isEqualToString:@"Red"]){
polylineView.strokeColor = [UIColor redColor];
}else if([lineColor isEqualToString:@"Blue"]){
polylineView.strokeColor = [UIColor blueColor];
}else if ([lineColor isEqualToString:@"Orange"]){
polylineView.strokeColor = [UIColor orangeColor];
}else if([lineColor isEqualToString:@"Green"]){
polylineView.strokeColor = [UIColor greenColor];
}else if([lineColor isEqualToString:@"Black"]){
polylineView.strokeColor = [UIColor blackColor];
}
return polylineView;
}else{
MKOverlayView *overlayToReturn = [[MKOverlayView alloc]initWithOverlay:overlay];
return overlayToReturn;
}
}

@end

关于iphone - MKMapView 加载时覆盖除 View 之外的所有内容?仅限iOS5<,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14072624/

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