2010-04-16 76 views
9

我已经在应用程序中使用引脚图像而不是标准引脚,现在我想给定制引脚赋予动画(如同标准引脚一样放置效果)。我怎样才能提供滴定动画效果自定义引脚图像?自定义引脚动画-MKMapView

+0

[这应该有助于](http://stackoverflow.com/questions/1857160/how-can-i-create-a-custom-pin-drop- animation-using-mkannotationview) – dwery 2010-04-17 14:23:46

回答

24

实施以下委托方法。

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { 
    MKAnnotationView *aV; 
    for (aV in views) { 
    CGRect endFrame = aV.frame; 

    aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - 230.0, aV.frame.size.width, aV.frame.size.height); 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.45]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
     [aV setFrame:endFrame]; 
    [UIView commitAnimations]; 

    } 
} 
+5

这个效果很好。应该标出正确答案。 – 2010-08-26 15:32:46

6

,如果你不删除所有引脚一次下降,但他们每个人有一个小的延迟,使得它看起来像有一种针效果雨也感觉更酷。类似于苹果本身所做的。使用这个:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { 
    MKAnnotationView *aV; 

    float delay = 0.00; 

    for (aV in views) { 
     CGRect endFrame = aV.frame; 

     aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - 430.0, aV.frame.size.width, aV.frame.size.height); 
     delay = delay + 0.01; 

     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDelay:delay]; 
     [UIView setAnimationDuration:0.45]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
     [aV setFrame:endFrame]; 
     [UIView commitAnimations]; 
    } 
} 
+0

是的,这很酷!谢谢 – PrasadW 2015-01-06 06:57:58

0

这对我很好。不记得在那里我发现它这里虽然

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { 
MKAnnotationView *aV; 

for (aV in views) { 

    // Don't pin drop if annotation is user location 
    if ([aV.annotation isKindOfClass:[MKUserLocation class]]) { 
     continue; 
    } 

    // Check if current annotation is inside visible map rect, else go to next one 
    MKMapPoint point = MKMapPointForCoordinate(aV.annotation.coordinate); 
    if (!MKMapRectContainsPoint(self.mapView.visibleMapRect, point)) { 
     continue; 
    } 

    CGRect endFrame = aV.frame; 

    // Move annotation out of view 
    aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - self.view.frame.size.height, aV.frame.size.width, aV.frame.size.height); 

    // Animate drop 
    [UIView animateWithDuration:0.3 delay:0.03*[views indexOfObject:aV] options:UIViewAnimationCurveLinear animations:^{ 

     aV.frame = endFrame; 

     // Animate squash 
    }completion:^(BOOL finished){ 
     if (finished) { 
      [UIView animateWithDuration:0.05 animations:^{ 
       aV.transform = CGAffineTransformMakeScale(1.0, 0.8); 

      }completion:^(BOOL finished){ 
       if (finished) { 
        [UIView animateWithDuration:0.5 animations:^{ 
         aV.transform = CGAffineTransformIdentity; 
        }]; 
       } 
      }]; 
     } 
    }]; 
    } 
} 
0

注意,在-mapView:didAddAnnotationViews:动画注解视图导致奇怪的效果时MKMapView.userTrackingMode等于MKUserTrackingModeFollowWithHeading。我只希望苹果公司能够为MKAnnotationView课程提供下载动画。

0

夫特3降动画

// animate annotation views drop 
func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) { 
     for annView in views { 

      // animate any annotation views except the user pin 
      if !(annView.annotation?.isKind(of: MKUserLocation.self))! { 
       let endFrame = annView.frame 
       annView.frame = endFrame.offsetBy(dx: 0, dy: -500) 
       UIView.animate(withDuration: 0.5, animations: { 
        annView.frame = endFrame 
       }) 
      } 
     }