3

次のように記述された正方形のオーバーレイを持つ MKMapView があります。

   CLLocationCoordinate2D coordsBg[5]={
    CLLocationCoordinate2DMake(31.750865,35.180882),
    CLLocationCoordinate2DMake(31.740331,35.180882),
    CLLocationCoordinate2DMake(31.740331,35.165452),
    CLLocationCoordinate2DMake(31.750865,35.165452),
    CLLocationCoordinate2DMake(31.750865,35.180882)
};     

MKPolygon *bg=[MKPolygon polygonWithCoordinates:coordsBg count:5];
[map addOverlay:bg];

ユーザーがオーバーレイの外にスクロールするのを制限したい。

そのための MKMapView スクロール ビューを制限できますか? それとも他の方法がありますか?

ありがとう

シャニ

4

1 に答える 1

0

数時間頭をぶつけた後、私はこの解決策にたどり着きました。

それは混同します:

この投稿: mkmapview のズーム レベルを設定する

そして、このリンク: @Anna Karenina コメントから私の質問へのmkmapview スクロールを制限します。

そして、これは私のコードです:

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{
    lastGoodMapRect = mapView.visibleMapRect;
    lastGoodRegion = mapView.region;
}

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{

    if (manuallyChangingMapRect) {
        manuallyChangingMapRect=NO;
        return;
    }

    if( [mapView zoomLevel] > 16 )
    {
        [mapView setCenterCoordinate:lastGoodRegion.center zoomLevel:16 animated:YES];
    }

    MKMapRect visibleRect = mapView.visibleMapRect;
    MKMapRect OverlayRect = bg.boundingMapRect;
    MKMapRect intersectionRect = MKMapRectIntersection(visibleRect,OverlayRect);

    //you can change the min and max zoom off course
    if(!MKMapRectEqualToRect(visibleRect,intersectionRect)){
        if( [mapView zoomLevel] < 15){

            [mapView setCenterCoordinate:lastGoodRegion.center zoomLevel:15 animated:YES];
        }else if( [mapView zoomLevel] > 16 )
        {
            [mapView setCenterCoordinate:lastGoodRegion.center zoomLevel:16 animated:YES];
        }else{
            manuallyChangingMapRect=YES;
            [mapView setVisibleMapRect:lastGoodMapRect animated:YES];
        }
    }

}
于 2012-06-22T21:06:08.683 に答える