2

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

我已经修改了一些我在这里找到的 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);
                    }];
                }];
            }
        }];

有任何想法吗?

4

2 回答 2

3

以下是开发人员对该功能的回复:https ://github.com/mapbox/mapbox-ios-sdk/issues/185该功能不在路线图中。

我想出了一个使用facebook pop 库[更新] 的解决方法:

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

这个想法是在动画开始之前隐藏注释层。

于 2014-05-28T20:23:53.990 回答
0

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

于 2014-02-10T02:56:39.667 回答