xcode 新的foursquare场地细节图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10979323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
New foursquare venue detail map
提问by animal_chin
I really love the way foursquare designed venue detail view. Especially the map with venue location in the "header" of view ... How was it done? Details are obviously some uiscrollview (maybe uitableview?) and behind it (in the header) there is a map so when you scroll up the map is beeing uncovered as the scroll view bounces... does anyone has an idea how to do this?
我真的很喜欢foursquare设计场地细节视图的方式。特别是在视图的“标题”中带有场地位置的地图......它是如何完成的?细节显然是一些 uiscrollview(也许是 uitableview?),在它后面(在标题中)有一张地图,所以当你向上滚动时,随着滚动视图的弹跳,地图会被发现......有没有人知道如何做到这一点?
回答by yonel
Here's the way I manage to reproduce it:-
这是我设法重现它的方式:-
You need a UIViewController
with a UIScrollView
as its view. Then, the content of the UIView
you add to your scrollview should look like this :-
你需要一个UIViewController
aUIScrollView
作为它的视图。然后,UIView
您添加到滚动视图的内容应如下所示:-
- The frame of the
MKMapView
have a negative y
position. In this case, we can only see 100pts of the maps in the default state (before dragging).
- You need to disable zooming and scrolling on your MKMapView instance.
-所述的框架的
MKMapView
具有负的y
位置。在这种情况下,我们只能看到默认状态下(拖动之前)的 100pts 地图。
- 您需要在 MKMapView 实例上禁用缩放和滚动。
Then, the trick is to move down the centerCoordinate
of the MKMapView
when you drag down, and adjust its center position.
然后,关键是要向下移动centerCoordinate
的MKMapView
,当你向下拖动,并调整其中心位置。
For that, we compute how much 1point represent as a delta latitude so that we know how much the center coordinate of the map should be moved when being dragged of x points on the screen :-
为此,我们计算 1point 代表多少纬度,以便我们知道在屏幕上拖动 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;
}
Once those properties are initialized, we need to implement the behavior of the UIScrollViewDelegate
. When we drag, we convert the move expressed in points to a latitude. And then, we move the center of the map using the half of this value.
一旦这些属性被初始化,我们需要实现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;
}
}
You get the same behavior as the foursquare app (but better: in the foursquare app, the maps recenter tends to jump, here, changing the center is done smoothly).
您将获得与foursquare 应用程序相同的行为(但更好:在foursquare 应用程序中,地图重心往往会跳跃,在这里,更改中心是顺利完成的)。
回答by user1218464
The example above is nice. If you need more help, I think they're using something very similar to RBParallaxTableViewController. https://github.com/Rheeseyb/RBParallaxTableViewController
上面的例子很好。如果您需要更多帮助,我认为他们正在使用与 RBParallaxTableViewController 非常相似的东西。https://github.com/Rheeseyb/RBParallaxTableViewController
It's essentially the same effect that Path uses for its header photo.
它本质上与 Path 用于其标题照片的效果相同。
回答by Thiago Pires
Yonel's answer is nice, but I found a problem as I have a pin at the center of the map. Because the negative Y, the point is hidden under my UINavigationBar.
Yonel 的回答很好,但我发现了一个问题,因为我在地图的中心有一个大头针。因为负Y,点隐藏在我的UINavigationBar下。
Then, I didn't set the Negative Y, and I correct my mapView.frame according the scroll offset.
然后,我没有设置负 Y,我根据滚动偏移更正了我的 mapView.frame。
My mapView is 320 x 160
我的地图视图是 320 x 160
_mapView.frame = CGRectMake(0, 160, 320, -160+y);
Hope this helps someone.
希望这可以帮助某人。