Question

So I'm using the MapBox SDK which is a fork of the RouteMe's map SDK for iOS. From what I can tell, the annotation stuff might be in here.

I've modified some CAAnimation code I found here to try achieve this. My code is below. Since I'm reasonably new to CAAnimation, the issue could be in that, or with the RouteMe code itself. It's just animating the layer which the annotation wraps.

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);
                    }];
                }];
            }
        }];

Any ideas?

Was it helpful?

Solution

Here is a reply from developers about the feature: https://github.com/mapbox/mapbox-ios-sdk/issues/185 The feature is not in the roadmap.

I came up with a workaround using facebook pop library [UPDATED]:

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

The idea is that you hide the annotation layers until the animation starts.

OTHER TIPS

So turns out that these Annotation objects have a layer property that is actually a CALayer, meaning you have to use CAAnimations on them, and not UIView animations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top