2014-01-28 44 views
2

因此,我使用MapBox SDK,它是適用於iOS的RouteMe地圖SDK的一個分支。從我所知道的,註釋的東西可能在這裏。使用CAAnimation在RMMapView上動畫RMPointAnnotation

我修改了一些CAAnimation代碼,我發現here試圖實現這一點。我的代碼如下。 由於我對CAAnimation相當陌生,因此可能出現這個問題,或者使用RouteMe代碼本身。它只是動畫註釋包裝的圖層。

RMPointAnnotation *point = [[RMPointAnnotation alloc] initWithMapView:self.mapView coordinate:CLLocationCoordinate2DMake([location[@"lat"] floatValue], [location[@"lon"] floatValue]) andTitle:@"App open"]; 



     point.image = [UIImage imageNamed:@"mapPin.png"]; 

     [self.mapView addAnnotation:point]; 

     CGRect endFrame = point.layer.frame; 

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

     // Animate drop 
     [UIView animateWithDuration:2.0 delay:0.04 options:UIViewAnimationOptionCurveLinear animations:^{ 

      point.layer.frame = endFrame; 

      // Animate squash 
     }completion:^(BOOL finished){ 
      if (finished) { 
       [UIView animateWithDuration:0.05 animations:^{ 
        point.layer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMake(1.0, 0, 0, 0.8, 0, + point.layer.frame.size.height*0.1)); 

       }completion:^(BOOL finished){ 
        [UIView animateWithDuration:0.1 animations:^{ 
         point.layer.transform = CATransform3DMakeAffineTransform(CGAffineTransformIdentity); 
        }]; 
       }]; 
      } 
     }]; 

任何想法?

回答

3

以下是有關該功能的開發者的回覆:https://github.com/mapbox/mapbox-ios-sdk/issues/185該功能不在路線圖中。

我想出了用一種變通方法facebook pop library [修訂]:

@property (strong, nonatomic) RMAnnotation *annotation; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.annotation = [[RMAnnotation alloc] initWithMapView:self.mapView 
               coordinate:self.mapView.centerCoordinate 
                andTitle:@"Drop pin"]; 

    self.annotation.layer.hidden = YES; 
    [self.mapView addAnnotation:self.annotation]; 

    POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY]; 
    anim.fromValue = @(0); 
    anim.toValue = @(self.view.center.y); 
    anim.springSpeed = 8; 
    anim.springBounciness = 4; 
    anim.delegate = self; 
    [self.annotation.layer pop_addAnimation:anim forKey:@"positionY"]; 
} 

-(void)pop_animationDidStart:(POPAnimation *)anim 
{ 
    self.annotation.layer.hidden = NO; 
} 

的想法是,你隱藏註釋層,直到動畫開始。

0

原來這些Annotation對象有一個實際上是CALayer的圖層屬性,這意味着你必須在它們上使用CAAnimations,而不是UIView動畫。

+0

您能否提供CAAnimations解決方案的代碼示例? –

+0

對不起,我不再訪問代碼庫,但我知道Facebook剛剛爲此https://code.facebook.com/projects/642915749111632/pop/ –

+1

發佈了一個庫感謝提示,Sam,圖書館似乎是很有用!我會使用流行音樂提交我的解答回覆 –