Bounce Animation on Google Map Marker in iOS ?? [Objective-c]

前端 未结 1 1238
慢半拍i
慢半拍i 2020-12-10 06:55

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

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

https://developers.google.com/maps/do

相关标签:
1条回答
  • 2020-12-10 07:45

    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 ...

    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.

    0 讨论(0)
提交回复
热议问题