我做了一个演示项目(移动-MKAnnotationView在github上演示)用于在地图上的下行驶的汽车是其链接汽车(译注)动画(如Uber应用)不工作
https://github.com/pratikbhiyani/Moving-MKAnnotationView
编辑我的代码基于给定答案的vinaut,但仍然问题是,当我们缩放或滚动地图动画时,我们缩放或滚动地图注释集合到原始角度一段时间,在ios 7和ios 6中分散注意力。
下面是我的演示项目
下面的屏幕截图是一些代码,我改变
- (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;
}
我的目标是相同的动车像Uber应用。
那么问题是什么?移动地图时,注释消失了吗? –
是的。并没有显示出它在ios 6中显示的流畅动画; –
尝试使用翻译变换而不是重新定位... – k06a