在iOS中的Google地图标记上弹跳动画? [目的-C] [英] Bounce Animation on Google Map Marker in iOS ?? [Objective-c]

查看:218
本文介绍了在iOS中的Google地图标记上弹跳动画? [目的-C]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



[动画像下面的链接,点击标记 - >],





获得这样的动画。像这样做

  GMSMarker * markerUser; 
NSTimer *计时器;
int imageScale;

在地图上添加标记

  imageScale = 15; 

CLLocationCoordinate2D position = CLLocationCoordinate2DMake(Userlat,Userlng);
markerUser = [GMSMarker markerWithPosition:position];
markerUser.title = @你在这里;
markerUser.icon = [self image:[UIImage imageNamed:@marker_user.png] scaledToSize:CGSizeMake(25.0f,40.0f)]; //初始标记大小
markerUser.appearAnimation = kGMSMarkerAnimationPop;
markerUser.infoWindowAnchor = CGPointMake(0.44f,0.30f);
markerUser.map = mapView_;

启动计时器在地图上添加标记时,

  timer = [NSTimer scheduledTimerWithTimeInterval:0.1 
target:self
选择器:@选择器(targetMethod :)
userInfo:无
重复:YES];

每隔0.1秒会触发一次tragetMethod,您可以在这里缩放图标图像并重新分配到标记图标

   - (void)targetMethod:(NSTimer *)timer {
$ b $ (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)];
}

}

这里是 缩放您的 UIImage

 <$ (CGImageSize,sizeItemsize,sizeImageSize,SizeImageSize,SizeImageSize,SizeImageSize,SizeImageSize)创建一个新的图像, )
{
return originalImage;
}

//创建绘图上下文
UIGraphicsBeginImageContextWithOptions(size,NO,0.0f);

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

//捕获结果图像
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//返回图片
返回图片;
}

这可能解决寻找这种动画的人的问题。

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_;

解决方案

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.

这篇关于在iOS中的Google地图标记上弹跳动画? [目的-C]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆