1

我有

  • 一个名为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保持在原来的位置。

我想出了一些可能的解释为什么会发生,但我不太确定如何克服这个问题。有什么建议么?

提前致谢。

4

1 回答 1

1

当您面对问题中的用户界面异常时,您肯定会错过设计中的某些内容。如果是这种情况,请检查您是否通过操作constraintstoryboard. 您可以通过constraint在代码中按下ctrl并拖动它来将其带入代码中,从而创建一个property. 然后,您可以轻松地constant在代码中更改约束的值,例如将相关视图移动到您在超级视图中想要的位置。

如果这不起作用,请尝试实施另一种 UI 设计方法。例如,您可以.xib为视图创建一个文件。这样,您只需在父视图中更改其框架即可轻松地在其父视图中操纵视图的每一个移动。这种方法比故事板中的方法更具弹性,但更难实现。

于 2016-04-24T17:26:43.043 回答