gpt4 book ai didi

iphone - 汽车(注释)动画(如 super 应用程序)无法正常工作

转载 作者:IT王子 更新时间:2023-10-29 07:55:44 28 4
gpt4 key购买 nike

我做了一个演示项目(来自 github 上的 Moving-MKAnnotationView 演示),用于在 map 上移动汽车,下面是它的链接

https://github.com/pratikbhiyani/Moving-MKAnnotationView

我根据 vinaut 给出的答案编辑我的代码,但仍然问题是,当我们缩放或滚动 map 动画时,在 ios 7 和 ios 6 中,当我们缩放或滚动 map 注释设置为它原来的角度一会儿。

下面是我的演示项目的屏幕截图

enter image description here

这是我修改的一些代码

- (void) setPosition : (id) posValue;
{
NSLog(@"set position");

//extract the mapPoint from this dummy (wrapper) CGPoint struct
MKMapPoint mapPoint = *(MKMapPoint*)[(NSValue*)posValue pointerValue];

CLLocationCoordinate2D coord = MKCoordinateForMapPoint(mapPoint);
CGPoint toPos;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {

toPos = [self.mapView convertCoordinate:coord toPointToView:self.mapView];
}
else
{
CGFloat zoomFactor = self.mapView.visibleMapRect.size.width / self.mapView.bounds.size.width;
toPos.x = mapPoint.x/zoomFactor;
toPos.y = mapPoint.y/zoomFactor;
}



[self setTransform:CGAffineTransformMakeRotation([self getHeadingForDirectionFromCoordinate:MKCoordinateForMapPoint(previousPoint) toCoordinate: MKCoordinateForMapPoint(mapPoint)])];

if (MKMapRectContainsPoint(self.mapView.visibleMapRect, mapPoint)) {

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];

animation.fromValue = [NSValue valueWithCGPoint:self.center];
animation.toValue = [NSValue valueWithCGPoint:toPos];
animation.duration = 1.0;
animation.delegate = self;
animation.fillMode = kCAFillModeForwards;
//[self.layer removeAllAnimations];
[self.layer addAnimation:animation forKey:POSITIONKEY];

//NSLog(@"setPosition ANIMATED %x from (%f, %f) to (%f, %f)", self, self.center.x, self.center.y, toPos.x, toPos.y);
}

self.center = toPos;

previousPoint = mapPoint;
}

我的目标是像在优步应用中一样移动汽车。

最佳答案

似乎 CLCoordinate2D/MKMapPoint/CGPoint 的转换函数发生了一些变化...

Detecting a point in a MKPolygon broke with iOS7 (CGPathContainsPoint)

注释消失了,因为 MkMapPoints 和 CGI​​Points 之间的转换不再起作用,如果你记录 CALayer 的“位置”,你将得到 View 之外的点。不知道为什么它在执行触摸事件时有效。

如果将函数更改为:

    - (void) setPosition : (id) posValue; 
{
//extract the mapPoint from this dummy (wrapper) CGPoint struct
MKMapPoint mapPoint = *(MKMapPoint*)[(NSValue*)posValue pointerValue];
CLLocationCoordinate2D coord = MKCoordinateForMapPoint(mapPoint);

CGPoint toPos = [self.mapView convertCoordinate:coord toPointToView:self.mapView];


if (MKMapRectContainsPoint(self.mapView.visibleMapRect, mapPoint)) {

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];

animation.fromValue = [NSValue valueWithCGPoint:self.center];
animation.toValue = [NSValue valueWithCGPoint:toPos];
animation.duration = 0.8;
animation.delegate = self;
animation.fillMode = kCAFillModeForwards;
//[self.layer removeAllAnimations];
[self.layer addAnimation:animation forKey:POSITIONKEY];

//NSLog(@"setPosition ANIMATED %x from (%f, %f) to (%f, %f)", self, self.center.x, self.center.y, toPos.x, toPos.y);
}

self.center = toPos;


}

它应该会再次工作。

关于iphone - 汽车(注释)动画(如 super 应用程序)无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19268080/

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