我正试图得到它,这样当你旋转iOS 7地图时,注释会随着相机的标题一起旋转。想象一下,我有必须始终指向北方的pin注释。
这一开始看起来很简单,应该有一个MKMapViewDelegate来获取相机旋转,但实际上没有。
我已经尝试使用地图代理来查询地图视图的
camera.heading
对象,但首先这些代理似乎只在旋转手势之前和之后调用一次:
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
我还尝试在camera.heading对象上使用KVO,但这不起作用,而且相机对象似乎是某种代理对象,只有在旋转手势完成后才会更新。
到目前为止,我最成功的方法是添加一个旋转手势识别器来计算旋转增量,并将其用于在区域更改代理开始时报告的相机标题。这在一定程度上起到了作用,但在OS7中,你可以“轻弹”你的旋转手势,它会增加速度,而我似乎无法跟踪。有没有办法实时跟踪摄像机的航向?
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{
heading = self.mapView.camera.heading;
}
- (void)rotationHandler:(UIRotationGestureRecognizer *)gesture
{
if(gesture.state == UIGestureRecognizerStateChanged) {
CGFloat headingDelta = (gesture.rotation * (180.0/M_PI) );
headingDelta = fmod(headingDelta, 360.0);
CGFloat newHeading = heading - headingDelta;
[self updateCompassesWithHeading:actualHeading];
}
}
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
[self updateCompassesWithHeading:self.mapView.camera.heading];
}