从事件的详细视图中,我想转到 MapViewController,放大注释,然后打开它的标注。以下是一些相关代码:
@interface MapViewController : UIViewController<MKMapViewDelegate>
...
- (void) viewWillAppear:(BOOL)animated
{
[self displayAnnotations];
}
- (void) viewDidAppear:(BOOL)animated
{
...
// Zoom in to event
[map setRegion:region animated:YES];
}
- (void) mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
...
regionAnimationEnded = YES;
[self selectAnnotation:a];
...
}
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
...
// check to see if the right view is in the array
...
annotationViewDidAppear = YES;
[self selectAnnotation:a];
...
}
- (void) selectAnnotation:(id<MKAnnotation>)annotation
{
if(annotationViewDidAppear && regionAnimationEnded)
{
if(!openedAnnotationFirstTime)
{
[map selectAnnotation:annotation animated:YES];
openedAnnotationFirstTime = YES;
}
}
}
这适用于 ios 6 模拟器,但在 ios 5.1 模拟器(和设备上)上,注释视图不可见,如文档中所述:
(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views 调用此方法时,指定的视图已经添加到地图中。
所以这取决于哪个先完成:如果区域更改动画最后完成并且注释视图已经出现,它可以工作,否则它不会。任何帮助,将不胜感激。