问题描述
我想在 iOS 中的 Google 地图标记上使用 Continuos Bounce 动画.
[动画如下链接,点击标记-->],
要获得这样的动画.这样做
GMSMarker *markerUser;NSTimer *定时器;int imageScale;
在地图上添加标记
imageScale=15;CLLocationCoordinate2D 位置 = 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 scheduleTimerWithTimeInterval:0.1目标:自己选择器:@选择器(目标方法:)用户信息:无重复:是];
每 0.1 秒会触发 tragetMethod ,在这里您可以缩放图标图像并重新分配给标记图标
-(void)targetMethod:(NSTimer *)timer {如果(图像比例
这里是方法 缩放您的
UIImage
- (UIImage *)image:(UIImage*)originalImage scaledToSize:(CGSize)size{//避免重复绘制if (CGSizeEqualToSize(originalImage.size, size)){返回原始图像;}//创建绘图上下文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 Map Marker 上的弹跳动画 ??[目标-c]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!