大佬教程收集整理的这篇文章主要介绍了ios – 在MapKit中沿弧线为可视元素设置动画,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
以下代码将在两点之间创建一个漂亮的弧.想象一下,动画视觉将代表沿着这条弧线飞行的飞机.
@H_489_9@-(void)addArc { CLLOCATIOnCoordinate2D sanFrancisco = { 37.774929,-122.419416 }; CLLOCATIOnCoordinate2D newYork = { 40.714353,-74.005973 }; CLLOCATIOnCoordinate2D pointsArc[] = { sanFrancisco,newYork }; // MKGeodesicPolyline *geodesic; geodesic = [MKGeodesicPolyline polylineWithCoordinates:&pointsArc[0] count:2]; // [self.mapView addOverlay:geodesic]; }
令人惊讶的是,MKGeodesicPolyline类足以提供它计算的各个点,通过points属性(给出MKMapPoints)或getCoordinates:range:方法(给出CLLOCATIOnCoordinate2Ds)来创建弧.
(实际上,该属性和方法在MKMultiPoint类中,MKPolyline是MKPolyline的子类,而MKGeodesicPolyline是MKPolyline的子类.)
只需在计时器上更新注释的坐标属性,地图视图就会自动移动注释.
注意:对于这么长的弧,会有数千个点.
这是一个非常简单粗略的例子,使用points属性(比getCoordinates:range:方法更容易使用)和performSELEctor:withObject:afterDelay ::
@H_489_9@//declare these ivars: MKGeodesicPolyline *geodesic; MKPointAnnotation *thePlane; int planePositionIndex; //after you add the geodesic overlay,initialize the plane: thePlane = [[MKPointAnnotation alloc] init]; thePlane.coordinate = sanFrancisco; thePlane.title = @"Plane"; [mapView addAnnotation:thePlane]; planePositionIndex = 0; [self performSELEctor:@SELEctor(updatePlanePosition) withObject:nil afterDelay:0.5]; -(void)updatePlanePosition { //this example updates the position in increments of 50... planePositionIndex = planePositionIndex + 50; if (planePositionIndex >= geodesic.pointCount) { //plane has reached end,stop moving return; } MKMapPoint nextMapPoint = geodesic.points[planePositionIndex]; //convert MKMapPoint to CLLOCATIOnCoordinate2D... CLLOCATIOnCoordinate2D nextCoord = MKCoordinateForMapPoint(nextMapPoint); //update the plane's coordinate... thePlane.coordinate = nextCoord; //schedule the next update... [self performSELEctor:@SELEctor(updatePlanePosition) withObject:nil afterDelay:0.5]; }
以上是大佬教程为你收集整理的ios – 在MapKit中沿弧线为可视元素设置动画全部内容,希望文章能够帮你解决ios – 在MapKit中沿弧线为可视元素设置动画所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。