【问题标题】:How to change View while we touch any annotation当我们触摸任何注释时如何更改视图
【发布时间】:2012-03-20 10:38:02
【问题描述】:

我想在 MKMapView 中添加一个功能。

我有一个带有许多注释的 mapView 现在我想要那个 .. 当我触摸任何注释时,整个视图都应该专注于该注释。即注释 A 在右上角,当我触摸 MapView 应该在中心显示 A 时。

【问题讨论】:

    标签: iphone uiview annotations location mkmapview


    【解决方案1】:
    - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
    {
       MKAnnotation *annotation= view.annotation;  // Get your annotaion here
       [map setCenterCoordinate:annotation.coordinate];  
    }
    
    //This will set the annotation in the centre of the map without zooming the map.
    

    【讨论】:

    • 谢谢,正是我想要的!
    【解决方案2】:

    在 Annotation Delegate 中,您必须设置地图视图的区域,指定中心

    - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
    {
       MKAnnotation *annotation= view.annotation;  // Get your annotaion here
       MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
       region.center.latitude=annotation.coordinate.latitude;
       region.center.longitude=annotation.coordinate.longitude;
       region.span.latitudeDelta=0.001f;
       region.span.longitudeDelta=0.001f;
       [mapView setRegion:region animated:YES];
      //Do your other stuffs here
    }
    

    【讨论】:

    • @whySoSerious...我不希望它放大太多...感染,而不是任何放大...只是它应该是该注释的中心。该怎么做?
    • 设置区域时,地图将移动到我们指定的中心位置。试试我给的东西
    • 是的,我试过了......但是当我触摸任何位置时,它会在该位置上放大太多......所以:( ..
    • 只需调整 latitudeDelta 和 longitudeDelta 值,使其不会缩放,而是会移动到中心。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多