Bounce Animation on Google Map Marker in iOS ?? [O

2019-01-18 14:45发布

I want a Continuos Bounce animation on Google Map Marker in iOS.

[animation like below link , Click on Marker -->] ,

https://developers.google.com/maps/documentation/javascript/examples/marker-animations

can we implement this bounce animation in iPhone?

i am Creating Marker with animated appear but i want to animate marker with Bounce Effect Continuously.

GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Delhi";
marker.zIndex=1;
marker.icon=[UIImage imageNamed:@"marker_user.png"];
// This is Only AppearAniamtion
marker.appearAnimation = kGMSMarkerAnimationPop; 
marker.infoWindowAnchor = CGPointMake(0.44f, 0.30f);
marker.map = mapView_;

1条回答
一夜七次
2楼-- · 2019-01-18 15:14

I wanted to add marker on Google map which will animate to indicated the current user. I was not able to get exact bounce animation like the link above i mentioned , for alternate way to highlight marker i did with using scale animation.
like this ... enter image description here

To get animation like this . do like this

 GMSMarker *markerUser;
 NSTimer *timer;
 int imageScale;

Add Marker on Map

 imageScale=15;

    CLLocationCoordinate2D position = CLLocationCoordinate2DMake(Userlat, Userlng);
    markerUser = [GMSMarker markerWithPosition:position];
    markerUser.title = @"You are here";
    markerUser.icon=[self image:[UIImage imageNamed:@"marker_user.png"] scaledToSize:CGSizeMake(25.0f,40.0f)];   // Initial Marker Size
    markerUser.appearAnimation = kGMSMarkerAnimationPop;
    markerUser.infoWindowAnchor = CGPointMake(0.44f, 0.30f);
    markerUser.map = mapView_;

Start Timer when marker is added on map, and change the icon of marker with different size .

 timer =  [NSTimer scheduledTimerWithTimeInterval:0.1
                                     target:self
                                   selector:@selector(targetMethod:)
                                   userInfo:nil
                                    repeats:YES];

at every 0.1 seconds tragetMethod will be fired , here you can scale the icon image and reassign to marker icon

-(void)targetMethod:(NSTimer *)timer {

    if (imageScale<30) {

        markerUser.icon=[self image:[UIImage imageNamed:@"marker_user.png"] scaledToSize:CGSizeMake(imageScale,imageScale*1.5)];

        imageScale+=1;

    }
    else{
        imageScale=15;

         markerUser.icon=[self image:[UIImage imageNamed:@"marker_user.png"] scaledToSize:CGSizeMake(imageScale,imageScale*1.5)];
    }

}

and here is the method that will scale your UIImage

- (UIImage *)image:(UIImage*)originalImage scaledToSize:(CGSize)size
{
    //avoid redundant drawing
    if (CGSizeEqualToSize(originalImage.size, size))
    {
        return originalImage;
    }

    //create drawing context
    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);

    //draw
    [originalImage drawInRect:CGRectMake(0.0f, 0.0f, size.width, size.height)];

    //capture resultant image
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    //return image
    return image;
}

This may solve problem of guys looking for such animation.

查看更多
登录 后发表回答