如何使iOS地图加Annotation有从空中掉下来的效果

玩过google app的都知道,我们在地图上加一个目的地的时候,annotationview是从上掉下来的,如何实现这样的效果?经过实战,我找到有两种方法可以完成这样的效果。

第一种是实现MKMapViewDelegate的一个方法,然后自已实现下落的动画效果,代码如下:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { 
	MKAnnotationView *aV; 
	for (aV in views) {
		CGRect endFrame = aV.frame;
		
		aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - 230.0, aV.frame.size.width, aV.frame.size.height);
		
		[UIView beginAnimations:nil context:NULL];
		[UIView setAnimationDuration:0.45];
		[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
		[aV setFrame:endFrame];
		[UIView commitAnimations];
		
	}
}


第二种方法很简单,只需要设置一个annotationview的属性值,也是在MKMapViewDelegate的一个方法中实现,代码如下:

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
	if (annotation == mV.userLocation) {
		return nil;
	}
	MKPinAnnotationView *pinView = nil;	
	static NSString *defaultPinID = @"custom pin";
	pinView = (MKPinAnnotationView *)[mV dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
	if ( pinView == nil )
	{
		pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
		[pinView setDraggable:YES];
		
	}
	pinView.pinColor = MKPinAnnotationColorRed;
	
	pinView.canShowCallout = YES;
	pinView.animatesDrop = YES;
	
	return pinView;
}


注意,就是

pinView.animatesDrop = YES;
起的作用。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值