ios – 新的foursquare场地详细地图
发布时间:2020-12-15 01:56:05 所属栏目:百科 来源:网络整理
导读:我真的很喜欢foursquare设计的场地详细视图。特别是地图与场地位置在“头”的视图…它是如何做的?细节显然是一些uiscrollview(也许uitableview?)和它后面(在标题)有一个地图,所以当你向上滚动地图是beeing被揭开,因为滚动视图反弹…有谁有一个想法如何做
我真的很喜欢foursquare设计的场地详细视图。特别是地图与场地位置在“头”的视图…它是如何做的?细节显然是一些uiscrollview(也许uitableview?)和它后面(在标题)有一个地图,所以当你向上滚动地图是beeing被揭开,因为滚动视图反弹…有谁有一个想法如何做到这一点?
解决方法
这是我设法复制的方式:
您需要一个具有UIScrollView的UIViewController作为其视图。然后,您添加到scrollview的UIView的内容应如下所示: – MKMapView的框架具有负y位置。在这种情况下,我们只能在默认状态(拖拽之前)看到100pt的地图。 那么诀窍就是向下移动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应用程序中,地图更新者倾向于跳跃,在这里,改变中心是顺利完成的)。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |