我有
- 一个名为MyMapViewController的视图控制器,它是情节提要中地图视图的委托,
- 一个名为MyListViewController的视图控制器(即故事板中的容器视图“ myContainerView ”),它是MyMapViewController的子视图控制器。
所以,我在情节提要中有以下内容:http: //pasteboard.co/1YAmM2ZU.png
在MyMapViewController中,我最初将myContainerView的框架设置如下,以便显示的唯一部分是MyMapViewController底部的导航栏:
CGRect destFrame = self.myContainerView.frame;
CGFloat navBarHeight = 44;
destFrame.origin.y = self.view.frame.size.height - navBarHeight;//to bottom of the screen; navigation bar yields 44 points
[UIView animateWithDuration:0
animations:^{
self.myContainerView.frame = destFrame;
}
];
在MyMapViewController中,我在地图上设置了一些注解,委托方法如下:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
NSLog(@"welcome into the map view annotation");
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.pinColor=MKPinAnnotationColorPurple;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"annotationProfile.png"]];
pinView.leftCalloutAccessoryView = profileIconView;
return pinView;
}
问题是,当我将地图滚动到用户自己的位置或地图上最初未显示的注释位置或单击其中一个注释时,myContainerView突然出现。(它移回情节提要中设置的位置。)但是,我希望myContainerView保持在原来的位置。
我想出了一些可能的解释为什么会发生,但我不太确定如何克服这个问题。有什么建议么?
提前致谢。