gpt4 book ai didi

iphone - 更新 iOS 7 map 相机旋转的 map 注释

转载 作者:可可西里 更新时间:2023-11-01 04:44:10 26 4
gpt4 key购买 nike

我正在努力做到这一点,以便在您旋转 iOS 7 map 时,注释会随着相机航向一起旋转。想象一下,我有必须始终指向北方的引脚注释。

这乍一看似乎很简单,应该有一个 MKMapViewDelegate 来获取相机旋转,但没有。

我试过使用 map 委托(delegate)来查询 map View 的 camera.heading 对象,但首先这些委托(delegate)似乎只在旋转手势之前和之后被调用一次:

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

我还尝试在 camera.heading 对象上使用 KVO,但这不起作用,而且相机对象似乎是某种代理对象,只有在旋转手势完成后才会更新。

到目前为止,我最成功的方法是添加一个旋转手势识别器来计算旋转增量,并将其与在区域更改委托(delegate)开始时报告的相机航向一起使用。这在一定程度上有效,但在 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];
}

最佳答案

遗憾的是,Apple 不提供任何 map 信息的实时更新。您最好的选择是设置一个 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];
}

关于iphone - 更新 iOS 7 map 相机旋转的 map 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19170254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com