放大特定的MKMapView框架

Rui*_*res 5 objective-c mkmapview foursquare ios

我的问题是不知何故与此相关的一个.但是对于iOS7,我想知道是否有更简单的方法.

所以基本上我有一个MKMapView视差效果,就像Foursquare应用程序.

在此输入图像描述

那么如何缩放可见矩形上的所有注释MKMapView呢?

现在我有一个工作解决方案,它使用一些值来抵消我的注释的纬度,但我觉得这很奇怪.


详情:

为了给地图一个视差效果(当你在滚动时UITableView,地图也在滚动),你需要保留地图的一部分地图.在我的情况下frame,我的MKMapView(0 -120; 320 390)和它的可见框架是 (0 0, 320 150);.所以这里的目标是能够显示可见的注释(放大)frame.

Ste*_*isk 2

像这样的东西应该可以工作,但我还没有真正尝试过代码:

MKAnnotation* firstAnnotaiton = annotations[0];

CLLocationDegrees north = firstAnnotation.coordinate.latitude;
CLLocationDegrees south = firstAnnotation.coordinate.latitude;
CLLocationDegrees east = firstAnnotation.coordinate.longitude;
CLLocationDegrees west = firstAnnotation.coordinate.longitude;

for (int i = 1; i < annotations.count; i++)
{
    MKAnnotation* annotation = annotations[i];

    if (north < firstAnnotation.coordinate.latitude)
        north = firstAnnotation.coordinate.latitude;
    if (south > firstAnnotation.coordinate.latitude)
        south = firstAnnotation.coordinate.latitude;
    if (west < firstAnnotation.coordinate.longitude)
        west = firstAnnotation.coordinate.longitude;
    if (east > firstAnnotation.coordinate.longitude)
        east = firstAnnotation.coordinate.longitude;
}

MKMapPoint upperLeft = MKMapPointForCoordinate(CLLocationCoordinate2DMake(
    north,
    west
));
MKMapPoint lowerRight = MKMapPointForCoordinate(CLLocationCoordinate2DMake(
    south,
    east
));

MKMapRect rect = MKMapRectMake(
    upperLeft.x,
    upperLeft.y,
    lowerRight.x - upperLeft.x,
    lowerRight.y - upperLeft.y
);

rect = [self.mapView mapRectThatFits:rect edgePadding:self.boundsInsets];

[self.mapView setVisibleMapRect:rect animated:animated];
Run Code Online (Sandbox Code Playgroud)

这里的关键是指定self.boundsInsets视图UIEdgeInsets实际大小与其可见边界之间的差异。