【问题标题】:MKMapView, pre-load annotationMKMapView,预加载注解
【发布时间】:2012-11-01 08:40:07
【问题描述】:

在我的新 ios 应用程序的不同位置显示小的MKMapView,其中滚动和用户交互被禁用。每张地图将始终有一个自定义注释。

如屏幕截图所示,一切正常。但是,有一个我不满意的小行为。加载包含MKMapView 的视图或单元格时,地图会立即出现,但在将注释添加到其中之前会有一小段延迟。我认为这是由于注释的工作方式(如UITableView)。

因为我的地图将始终包含一个注释,有没有办法强制它在地图实际出现在屏幕上之前预先加载到地图上。当MKMapView 包含在滚动时重新加载的tableview 单元格中时,我不想要那个非常烦人的小延迟。 欢迎任何其他想法。

谢谢

【问题讨论】:

    标签: ios mkmapview mkannotation mkannotationview


    【解决方案1】:

    我不知道如何测试它,但是 set 呢:

    myPinView.animatesDrop = NO;
    

    在您的 viewForAnnotation 委托中,因为默认设置为 YES 值。

    【讨论】:

      【解决方案2】:

      我不知道你在代码中究竟做了什么,但也许它对你有帮助。

      - (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id <MKAnnotation>)annotation
      {
       MKPinAnnotationView* pv = (MKPinAnnotationView*)[mv dequeueReusableAnnotationViewWithIdentifier:reuse];
          if ( pv == nil )
          {
              pv = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuse] autorelease];   
              [pv setAnimatesDrop:YES]; // replace this line with the following line
              [pv setAnimatesDrop:NO];
          }
      
          [pv setAnnotation:annotation];
      
          return pv;
      }
      

      【讨论】:

        【解决方案3】:

        为什么不在初始化期间将 MapView 设置为隐藏,然后添加注释后,将触发此方法:

        - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
        {
            // reveal map
            mapView.hidden = NO;
        
            // -----------------------------------------------------------------
            // ALTERNATIVE WAY TO SHOW MAP VIEW WITH SMOOTH FADE IN
            //
            // if you want you can even animate the fading in of the 
            // note: this means you need to remove the above line
            // and you also need to set mapView.alpha = 0 during initialsation
            // instead of using mapView.hidden = YES
            // -----------------------------------------------------------------
            [UIView animateWithDuration:0.5 animation:^{ 
                mapView.alpha = 1;
            }];
        }
        

        (参考:http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/intfm/MKMapViewDelegate/mapView:didAddAnnotationViews:)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-03-30
          • 1970-01-01
          • 2011-12-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多