大佬教程收集整理的这篇文章主要介绍了ios – 新的foursquare场地详细地图,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
您需要一个具有UIScrollView的UIViewController作为其视图。然后,您添加到scrollview的UIView的内容应如下所示:
– MKMapView的框架具有负y位置。在这种情况下,我们只能在默认状态(拖拽之前)看到100pt的地图。
– 您需要在MKMapView实例上禁用缩放和滚动。
那么诀窍就是向下移动MKMapView的中心坐标,当你向下拖动时,调整它的中心位置。
为此,我们计算1点表示为三角纬度,以便我们知道在屏幕上拖动x点时应该移动地图的中心坐标:
- (void)viewDidLoad { [super viewDidLoad]; UIScrollView* scrollView = (UIScrollView*)self.view; [scrollView addSubview:contentView]; scrollView.contentSize = contentView.frame.size; scrollView.delegate = self; center = CLLOCATIOnCoordinate2DMake(43.6010,7.0774); mapView.region = MKCoordinateRegionMakeWithDistance(center,1000,1000); mapView.centerCoordinate = center; //We compute how much latitude represent 1point. //so that we kNow how much the center coordinate of the map should be moved //when being dragged. CLLOCATIOnCoordinate2D referencePosition = [mapView convertPoint:CGPointMake(0,0) toCoordinateFromView:mapView]; CLLOCATIOnCoordinate2D referencePosition2 = [mapView convertPoint:CGPointMake(0,100) toCoordinateFromView:mapView]; deltaLatFor1px = (referencePosition2.latitude - referencePosition.latitudE)/100; }
一旦这些属性被初始化,我们需要实现UIScrollViewDelegate的行为。当我们拖动时,我们将以点表示的移动转换为纬度。然后,我们使用这个值的一半移动地图的中心。
- (void)scrollViewDidScroll:(UIScrollView *)theScrollView { CGFloat y = theScrollView.contentOffset.y; // did we drag ? if (y<0) { //we moved y pixels down,how much latitude is that ? double deltaLat = y*deltaLatFor1px; //Move the center coordinate accordingly CLLOCATIOnCoordinate2D newCenter = CLLOCATIOnCoordinate2DMake(center.latitude-deltaLat/2,center.longitudE); mapView.centerCoordinate = newCenter; } }
你得到与foursquare应用程序相同的行为(但更好的是:在foursquare应用程序中,地图更新者倾向于跳跃,在这里,改变中心是顺利完成的)。
以上是大佬教程为你收集整理的ios – 新的foursquare场地详细地图全部内容,希望文章能够帮你解决ios – 新的foursquare场地详细地图所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。