在iOS 7地图相机旋转上更新地图注释
问题描述:
我想要获得它,以便在旋转iOS 7地图时注释随相机标题一起旋转。想象一下,我有任何时候都必须指向北方的针注释。在iOS 7地图相机旋转上更新地图注释
这看起来很简单,首先,应该有一个MKMapViewDelegate用于获取相机旋转,但没有。
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
我使用志愿也试过:
我使用地图代表们然后查询地图视图的camera.heading
对象,但首先这些代表似乎只是之前和旋转手势之后,曾经一度被称为尝试在camera.heading对象上,但这不起作用,并且相机对象似乎是某种只在旋转手势完成时才更新的代理对象。
到目前为止,我最成功的方法是添加一个旋转手势识别器来计算旋转增量,并将其与区域更改代表开始时报告的摄像头标题一起使用。这很有用,但在OS 7中,您可以“轻拂”您的旋转手势,并增加了我无法跟踪的速度。有没有办法实时追踪摄像头的方向?
- (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];
}
答
不幸的是,苹果公司并未给出任何地图信息的实时更新。您最好的选择是设置一个CADisplayLink,并在更改时更新所需的任何内容。像这样的东西。
@property (nonatomic) CLLocationDirection *previousHeading;
@property (nonatomic, strong) CADisplayLink *displayLink;
- (void)setUpDisplayLink
{
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkFired:)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}
- (void)displayLinkFired:(id)sender
{
double difference = ABS(self.previousHeading - self.mapView.camera.heading);
if (difference < .001)
return;
self.previousHeading = self.mapView.camera.heading;
[self updateCompassesWithHeading:self.previousHeading];
}
Thanks @Ross,似乎这是唯一的选择。令人沮丧。我可能会提交一个错误报告。 – Electron