Auto (Annotation) animation (wie uber-app) funktioniert nicht

Machte ich ein demo-Projekt (von Moving-MKAnnotationView demo auf github) für fahrenden Auto auf der folgenden Karte ist die Verknüpfung

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

Bearbeite ich meine code auf der Grundlage der gegebenen Antwort durch vinaut aber noch problem ist, dass, wenn wir uns vergrößern oder die Karte zu scrollen animation erhalten ablenken in ios 7 und in ios 6, wenn wir den zoom oder das scrollen der map-annotation festgelegt, um die ursprünglichen Winkel für eine Weile.

Unten ist ein Screenshot von meinem Demo-Projekt

Auto (Annotation) animation (wie uber-app) funktioniert nicht

Hier ist etwas code, den ich ändern

- (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;
}

Mein Ziel ist es, sich zu bewegen Auto der gleiche wie in uber-app.

  • Was ist also das problem? Ihre Anmerkungen verschwinden, wenn Sie die Karte verschieben?
  • ja. und seine nicht zeigen glatte animation, wie es zeigt in ios 6;
  • Versuchen Sie, zu verwenden, übersetzung-Transformation anstelle der Neupositionierung...
  • Ok , ich werde versuchen
  • können Sie veröffentlichen Sie Ihren code in der animation? und wie erkennen Sie, dass Auto drehen müssen, wie am Rande der Straße ?
  • github.com/pratikbhiyani/Moving-MKAnnotationView
  • es läuft auf VORGEGEBENE Koordinaten...
  • können Sie die Idee, sich zu bewegen-pin mit lat lang, die bekomme ich aus der api-instand-pre Koordinaten? für swift

Schreibe einen Kommentar