我以编程的方式旋转一个MKMapView,使用一个简单的NSTimer不断增加MKMapCamera的heading属性,该属性工作正常(导致地图在华盛顿纪念碑周围缓慢旋转)。
不是让地图围绕它的中心旋转,我想让它围绕地图的底部旋转。解决方案应该很简单,将地图的高度加倍,然后围绕现在位于屏幕底部的中心旋转。将地图的高度加倍后,它仍然围绕屏幕的中心旋转,而不是围绕地图框架的中心旋转。
苹果似乎在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];
}发布于 2014-01-24 05:53:21
我知道这是一个古老的问题,但这是一个非常令人沮丧的问题。Autolayout和MapKit在幕后做了一些时髦的事情。我注意到mapView渲染自动将我的地图视图居中,将用户位置放在屏幕中央。在我这样做之前,任何数量的偏移、约束、变换、超级视图都不能使地图不在屏幕上居中。
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
CLLocationDegrees heading = newHeading.trueHeading >= 0 ? newHeading.trueHeading : newHeading.magneticHeading;
//ACCOUNT FOR LANDSCAPE ORIENTATION IN HEADING
if(self.interfaceOrientation == UIInterfaceOrientationLandscapeRight){
heading += 180;
if(heading > 360) heading -= 360;
}
//OFFSET MAP
CGPoint p = [_mapView convertCoordinate:_currentLocation toPointToView:_mapView];
CGPoint p2 = CGPointMake(p.x, p.y - MAP_VERTICAL_OFFSET);
CLLocationCoordinate2D t = [_mapView convertPoint:p2 toCoordinateFromView:_mapView];
[_aCamera setHeading:heading];
[_aCamera setCenterCoordinate:t];
[_mapView setCamera:_aCamera];
}https://stackoverflow.com/questions/19132799
复制相似问题