Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 缩放特定的MKMapView帧_Ios_Objective C_Mkmapview_Foursquare - Fatal编程技术网

Ios 缩放特定的MKMapView帧

Ios 缩放特定的MKMapView帧,ios,objective-c,mkmapview,foursquare,Ios,Objective C,Mkmapview,Foursquare,我的问题与此有关。但是对于iOS7,我想知道是否有一种更简单的方法可以做到这一点 所以基本上我有一个MKMapView使用视差效果,很像Foursquare应用程序 那么如何缩放MKMapView的可见矩形上的所有注释呢 现在我有一个可行的解决方案,它使用一些值来抵消注释的纬度,但我发现这样做非常奇怪 详细信息: 为了使地图具有视差效果(当您在UITableView上滚动时,地图也在滚动),您需要将地图的一部分放在表格下方。在我的例子中,MKMapView的框架是(0-120;320 390

我的问题与此有关。但是对于iOS7,我想知道是否有一种更简单的方法可以做到这一点

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

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

现在我有一个可行的解决方案,它使用一些值来抵消注释的纬度,但我发现这样做非常奇怪


详细信息:


为了使地图具有视差效果(当您在
UITableView
上滚动时,地图也在滚动),您需要将地图的一部分放在表格下方。在我的例子中,MKMapView的
框架是
(0-120;320 390)
,它的可见框架是
(0 0,320 150)。因此,这里的目标是能够在可见的
帧上显示注释(放大)

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

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];
MKAnnotation*firstannotation=annotations[0];
CLLocationDegrees north=firstAnnotation.coordinate.latitude;
CLLocationDegrees south=firstAnnotation.coordinate.latitude;
CLLocationDegrees east=firstAnnotation.coordinate.longitude;
CLLocationDegrees west=firstAnnotation.coordinate.longitude;
对于(int i=1;i第一注释.坐标.纬度)
南=第一注释。坐标。纬度;
if(西<第一注释.坐标.经度)
west=firstAnnotation.coordinate.longitude;
if(东>第一注释.坐标.经度)
east=firstAnnotation.coordinate.longitude;
}
MKMapPoint左上=MKMapPointForCoordinate(CLLocationCoordinate2DMake(
北,
西
));
MKMapPoint lowerRight=MKMapPointForCoordinate(CLLocationCoordinate2DMake(
南方
东
));
MKMapRect rect=MKMapRectMake(
左上角.x,
左上角,y,
右下角x-左上角x,
右下角y-左上角y
);
rect=[self.mapView mapRectThatFits:rect edgePadding:self.BoundsSets];
[self.mapView setVisibleMapRect:rect动画:动画];

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

我不完全确定是否理解了您的问题,但如果不只是更详细地解释,我可能可以为您解决它。我添加了更多细节@StefanFiskcool,那么这应该行得通,只需为顶部和底部创建一个120px的插图。+您可能需要的任何额外边距(至少是用于注释的任何图形半径的一半)我在什么位置指定
插图和缩放级别?