1

私は持っている

  • ストーリーボードにあるマップ ビューのデリゲートであるMyMapViewControllerという名前のビュー コントローラー、
  • MyMapViewControllerの子ビュー コントローラーであるMyListViewControllerという名前のビュー コントローラー (つまり、ストーリーボードのコンテナー ビュー ' myContainerView ') 。

したがって、ストーリーボードには次のものがあります: 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;
}

問題は、マップをユーザー自身の場所、またはマップに最初に表示されていない注釈の場所にスクロールしたり、注釈の 1 つをクリックしたりすると、myContainerViewが突然表示されることです。(ストーリーボードで設定した場所に戻ります。)ただし、myContainerViewは元の場所にとどめておいてください。

なぜそれが起こるのかいくつかの可能な説明を思いつきましたが、どうすればこの問題を克服できるのかよくわかりません. 助言がありますか?

前もって感謝します。

4

1 に答える 1

1

質問のようなユーザー インターフェースの異常に直面した場合、デザインに欠けているものがあるはずです。この場合は、 でconstraint定義した を操作して問題を解決するかどうかを確認してくださいstoryboardconstraintコード内で を押しctrlてドラッグするだけで をコードに取り込み、 property. 次に、コード内の制約の値を簡単に変更できますconstant。たとえば、関連するビューをスーパービューの必要な場所に移動することができます。

これがうまくいかない場合は、別の UI 設計アプローチを実装してみてください。たとえば.xib、ビュー用のファイルを作成できます。このようにして、スーパービュー内のフレームを変更するだけで、スーパービュー内のビューのすべての動きを簡単に操作できます。このアプローチは、ストーリーボードのアプローチよりもはるかに弾力性がありますが、実装が困難です。

于 2016-04-24T17:26:43.043 に答える