新的四方场地详细地图

我真的很喜欢foursquaredevise场地细节视图的方式。 特别是地图位置在“标题”视图中…怎么做? 详细信息显然是一些uiscrollview(也许uitableview?)和它后面(在标题中)有一个地图,所以当你滚动地图是beeing发现滚动视图反弹…有没有人有一个想法如何做到这一点?

在这里输入图像说明

这是我设法重现它的方式:

你需要一个UIScrollView作为其视图的UIViewController 。 然后,你添加到你的滚动视图的UIView的内容应该看起来像这样:

在这里输入图像说明MKMapView的框架有一个负的y位置 。 在这种情况下,我们只能看到默认状态(拖动之前)的地图的100pts。
– 你需要禁用缩放和滚动你的MKMapView实例。

然后,诀窍就是当您向下拖动MKMapView的中心坐标时,调整其中心位置。

为此,我们计算1点表示多less纬度,以便我们知道在屏幕上拖动x点时地图的中心坐标应移动多less。

 - (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 app相同的行为(但更好的是:在foursquare app中,maps recenter往往会跳跃,在这里,改变中心是顺利的)。

上面的例子很好。 如果你需要更多的帮助,我想他们正在使用类似于RBParallaxTableViewController的东西。 https://github.com/Rheeseyb/RBParallaxTableViewController

这与Path用于标题照片的效果基本相同。

Yonel的回答很好,但是我发现一个问题,因为我在地图的中心有一个针。 因为负的Y,这个点隐藏在我的UINavigationBar下。

然后,我没有设置负Y,并根据滚动偏移量更正了我的mapView.frame。

我的mapView是320 x 160

 _mapView.frame = CGRectMake(0, 160, 320, -160+y); 

希望这有助于某人。