我正在使用简单的 NSTimer 以编程方式旋转 MKMapView,以不断增加 MKMapCamera 的标题属性,该属性按预期工作(导致地图围绕华盛顿纪念碑缓慢旋转)。
我不想让地图围绕其中心旋转,而是希望它围绕地图底部旋转。解决方案应该很简单,将地图的高度加倍,然后围绕其中心旋转,该中心现在位于屏幕底部。在将地图高度加倍后,它仍然围绕屏幕中心而不是地图框的中心旋转。
苹果似乎在 MKMapView 中添加了额外的逻辑,以保持右下角的“法律”标签,无论地图框是什么,我认为这也是导致此问题的原因。
有什么想法可以强制地图围绕地图底部而不是中心旋转吗?
- (void)setupMap {
// Works as expected (rotates around center of screen)
CGRect mapFrame = self.view.bounds; // works as expected
// Doesn't work as expected (also rotates around the center of the screen)
//mapFrame.size.height = self.view.frame.size.height*2;
// Create/show MKMapView
testMapView = [[MKMapView alloc] initWithFrame:mapFrame];
[self.view addSubview:testMapView];
// Zoom into the Washington Monument with a pitch of 60°
MKMapCamera *aCamera = [MKMapCamera camera];
[aCamera setCenterCoordinate:CLLocationCoordinate2DMake(38.8895, -77.0352)];
[aCamera setAltitude:400];
[aCamera setPitch:60];
[testMapView setCamera:aCamera];
// Begin rotating map every 1/10th of a second
NSTimer *aTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(rotateMap) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:aTimer forMode:NSDefaultRunLoopMode];
}
- (void)rotateMap {
MKMapCamera *aCamera = [testMapView camera];
[aCamera setHeading:aCamera.heading+1];
[testMapView setCamera:aCamera];
}