0

次のように xib ファイルからロードされるカスタム ビューを作成しました。

- (id)initWithFrame:(CGRect)frame {
  self = [super initWithFrame:frame];
  if (self) {
    // Initialization code.
    [[NSBundle mainBundle] loadNibNamed:@"TachoView" owner:self options:nil];
    [self addSubview:self.view];
    [self initUi];
  }
  return self;
}

デバイスの向きが変わると、一部のサブビューの自動サイズ変更と配置で問題が発生しています。これらのスクリーンショットは、動作を説明しています。

viewDidLoad の後、すべてが正常に見えます。

ここに画像の説明を入力

横向きモードに回転した後も、レイアウトは問題ありません。

ここに画像の説明を入力

しかし、protrait に戻すと、次のようになります。

ここに画像の説明を入力

同じファイル .h、.m、および .xib は、単一ビューのダミー プロジェクトでテストすると正常に動作します。したがって、xib での配置とサイズ変更の設定は問題ないと思います。私のアプリとの違いは、ビューがスクロールビューに配置され、他のいくつかのビューがあることです。向きを変更すると、これらすべてのビューのサイズが変更されるため、すべてが期待どおりにレイアウトされます。関連するコードは、最も内側の for ループです。

-(void) viewWillLayoutSubviews {
    float h = self.view.frame.size.height;
    float w = self.view.frame.size.width;

    // set the size of the vertical scrollview
    verticalView.frame = CGRectMake(0, 0, w, h * gridHeight);
    verticalScrollView.frame = CGRectMake(0, 0, w, h);
    [verticalScrollView setContentSize:CGSizeMake(w, h * gridHeight)];
    [verticalScrollView layoutIfNeeded];

    // set the size of the horizontal scrollviews
    for (int i=0; i<verticalView.subviews.count; i++) {
        UIScrollView *scrollView = (UIScrollView *) [verticalView.subviews objectAtIndex:i];
        UIView *container = (UIView *) [[scrollView subviews] objectAtIndex:0];
        int subviewCount = container.subviews.count;
        scrollView.frame = CGRectMake(0, h*i, w, h);
        [scrollView setContentSize:CGSizeMake(w * subviewCount, h)];
        container.frame = CGRectMake(0, 0, w * subviewCount, h);

        // set the size of the actual views
        for (int j=0; j<container.subviews.count; j++) {
            UIView *view = [container.subviews objectAtIndex:j];
            // FIXME manchmal crashed hier die WebView. Muss das hier im
            // ui thread ausgeführt werden? wird diese methode nicht vom
            // ui thread aufgerufen?
            view.frame = CGRectMake(w*j, 0, w, h);
        }
    }
}

2 回目のオリエンテーションの変更で何が問題になっているのでしょうか? ビュー全体を手動でレイアウトすることもできましたが、自動サイズ変更機能でも可能だと思います。

4

1 に答える 1

0

UIViewAutoresizingMasks がこれらのように設定されていることを確認してください

1) Liegezeiten ラベルは flexibleWidth です

2) Wert in % ラベルには、flexibleTopMargin、flexibleWidth、および flexibleRightMargin のみが必要です。

3) 以下の番号ラベル (64、40、20):

  • 64には、flexibleTopMargin、flexibleWidth、およびflexibleRightMarginが必要です
  • 40 には、flexibleTopMargin、flexibleWidth、flexibleRightMargin、flexibleLeftMargin が必要です。
  • 20 には、flexibleTopMargin、flexibleWidth、flexibleLeftMargin が必要です。
于 2012-08-02T14:26:54.863 に答える