旋转MKMapView [英] rotating MKMapView

查看:156
本文介绍了旋转MKMapView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作应用程序,其中MKMapView显示用户位置。到目前为止,非常好:

I have a working app with an MKMapView showing user location. So far, so good:

- (void)viewDidLoad {
   ...
   [myMapView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
   [myMapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
}

现在,我允许界面轮换:

Now, I allow interface rotations:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return YES;
}

如果我现在将设备和中心转到用户位置

If I now turn the device and center to the user location

   [myMapView setCenterCoordinate:[myMapView userLocation].coordinate animated:YES];

mapView将按预期旋转,但用户位置不会居中,而是位于底部屏幕(距离顶部的距离与纵向模式相同)。

The mapView will rotate as expected, but the user location will not be centered, but on the bottom of the screen (distance from top stays the same as in portrait mode).

我希望它居中,但是...

I expect it to be centered, though...

任何想法?

推荐答案

尝试在 setAutoresizingMask中包含高度:这样当superview在旋转时改变其高度时,地图视图的高度将自动改变。现在,只有宽度正在调整大小,因此地图中心的y位置不会改变。

Try including height in the setAutoresizingMask: so that the map view's height will automatically change when the superview changes its height on rotation. Right now, only the width is resizing and so the y position of the map's center doesn't change.

所以这一行:

[myMapView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

应为:

[myMapView setAutoresizingMask: 
    (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];



此外,您不需要手动将地图居中于用户位置,如果您将跟踪模式设置为 MKUserTrackingModeFollow (地图将自动执行)。您可能已尝试手动居中以修复高度问题,但修复自动调整遮罩应消除显式居中的需要。


Additionally, you shouldn't need to manually center the map on the user location if you are setting the tracking mode to MKUserTrackingModeFollow (the map will do it automatically). You may have tried manually centering it to fix the height issue but fixing the autoresizing mask should eliminate the need for the explicit centering.

这篇关于旋转MKMapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆