使用CAAnimation在RMMapView上动画RMPointAnnotation

时间:2014-01-28 02:05:30

标签: mkmapview caanimation route-me

所以我使用的是MapBox SDK,它是RouteMe的iOS地图SDK的一个分支。据我所知,注释内容可能就在这里。

我修改了一些我发现的here CAAnimation代码来尝试实现这一点。我的代码如下。 由于我是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);
                    }];
                }];
            }
        }];

有什么想法吗?

2 个答案:

答案 0 :(得分: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;
}

我们的想法是隐藏注释图层,直到动画开始。

答案 1 :(得分:0)

事实证明,这些Annotation对象具有一个实际上是CALayer的图层属性,这意味着您必须对它们使用CAAnimations,而不是UIView动画。