iPad 上的 MKMapView 渲染问题

发布于 2024-10-19 19:43:59 字数 1222 浏览 3 评论 0原文

我的问题仅出现在 iPad 上。 MKMapView 总是有未渲染的部分(下图右侧)。一旦我触摸这个窗口,地图视图就会很好地重新绘制自己。但它永远不会立即正确渲染。此问题出现在 iOS 4.2 以及 iOS 3.2 的模拟器和设备中。构造 MKMapView 的代码如下:

- (void)viewDidLoad {
      [super viewDidLoad];  
      mapview = [[[MKMapView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,230)] autorelease]; // because of apples bug
      mapview.autoresizingMask = UIViewAutoresizingFlexibleWidth;
      MKCoordinateSpan globe = MKCoordinateSpanMake(100, 100);

      CLLocationCoordinate2D worldCenter; worldCenter.latitude = 42.032974; worldCenter.longitude =21.359375;

      MKCoordinateRegion worldmap = MKCoordinateRegionMake(worldCenter, globe);
      mapview.region = worldmap;
      mapview.zoomEnabled = NO;
      mapview.showsUserLocation = YES;
      mapview.delegate = self;

      NSRange theRange;
      theRange.location = 1;
      theRange.length = [annotations count]-1;

      [mapview addAnnotations:[annotations subarrayWithRange:theRange]];
      [self.view addSubview:mapview];   
}

该问题仅在横向方向上表现出来。

不正确的跨度 更新

这是我触摸视图后它的跨越方式。 正确跨度

My problem occurs only on iPad. There is always unrendered portion of MKMapView(right side on the picture below). As soon as I touch this window the mapview repaints itself just fine. But it never renders correctly right away. This problem occures in iOS 4.2 as well as in iOS 3.2 in Simulator and the Device. The code that constructs MKMapView is right below:

- (void)viewDidLoad {
      [super viewDidLoad];  
      mapview = [[[MKMapView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,230)] autorelease]; // because of apples bug
      mapview.autoresizingMask = UIViewAutoresizingFlexibleWidth;
      MKCoordinateSpan globe = MKCoordinateSpanMake(100, 100);

      CLLocationCoordinate2D worldCenter; worldCenter.latitude = 42.032974; worldCenter.longitude =21.359375;

      MKCoordinateRegion worldmap = MKCoordinateRegionMake(worldCenter, globe);
      mapview.region = worldmap;
      mapview.zoomEnabled = NO;
      mapview.showsUserLocation = YES;
      mapview.delegate = self;

      NSRange theRange;
      theRange.location = 1;
      theRange.length = [annotations count]-1;

      [mapview addAnnotations:[annotations subarrayWithRange:theRange]];
      [self.view addSubview:mapview];   
}

The problem manifests itself only in Landscape orientation.

Incorrect span
UPDATE

This is how it spans after I touched the view.
Correct span

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉南桥 2024-10-26 19:43:59

尽管如此,这是苹果的错误。在 iPad 横向模式下,您的经度跨度可能不足以覆盖地球 360 度。它应该随着缩放自动缩放,但事实并非如此。仅当您的 centerMap 恰好位于 0 度经度时,它才会正确自动缩放。诡异的。

解决方法:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    CLLocationCoordinate2D worldCenter; worldCenter.latitude = 42.032974; 
    worldCenter.longitude = UIDeviceOrientationIsLandscape(toInterfaceOrientation)? 0.0 : 21.359375;
    mapview.centerCoordinate = worldCenter;
}

Nonetheless it's Apple's bug. In iPad-landscape mode your longtitude span may not be enough to cover 360degree of the globe. it should autoscale with zoom, but it doesn't. it autozooms properly only if your centerMap is exactly at 0 degree longitude. Weird.

Workaround:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    CLLocationCoordinate2D worldCenter; worldCenter.latitude = 42.032974; 
    worldCenter.longitude = UIDeviceOrientationIsLandscape(toInterfaceOrientation)? 0.0 : 21.359375;
    mapview.centerCoordinate = worldCenter;
}
断桥再见 2024-10-26 19:43:59

我对您的代码进行了快速测试并得到了相同的结果(这是我所期望的)。我仍然认为这不是地图本身的问题,而是您设置中心坐标和地图跨度的方式的问题。您试图以最大跨度将地图居中到左侧太远,并且地图填充整个屏幕并保持中心点的唯一方法是它自行拉伸,这是不可取的。如果将纬度和经度设置为 0,您将获得相同的视图,而不会丢失部分。

I did a quick test with your code and get the same result (which I expected). I still think it is not an issue with the map itself but with the way you are setting your center coordinates plus map span. You're trying to center the map too far to the left with max span and the only way for the map to fill the entire screen and maintain the center point would be for it to stretch itself, which is not desirable. If you set lat and long to 0 you get the same view without the missing part.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文