我想在Google地圖上添加標記,該標記將動畫顯示當前用戶。 我無法像上面提到的鏈接那樣獲得確切的跳動動畫,這是替代方式來突出顯示我使用縮放動畫製作的標記。
這樣子...
要得到這樣的動畫。就這樣
GMSMarker *markerUser;
NSTimer *timer;
int imageScale;
添加標記地圖
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_;
啓動計時器當標記在地圖上添加和更改標記的圖標具有不同的尺寸。
timer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(targetMethod:)
userInfo:nil
repeats:YES];
每0.1秒tragetMethod將被解僱的,在這裏你可以規模的圖標圖像並重新分配給標記圖標
-(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)];
}
}
這裏是方法將規模的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;
}
這可能解決尋找這種動畫的人的問題。