0

iOS ユニバーサル アプリで発生している問題を理解しようとしています。私は UIScrollView を持っており、そのページがデバイスの全寸法を占め、回転時にそれ自体を調整する必要があります。

私のviewDidLoadメソッドでは、次のようにテストしています:

NSArray *colors = [NSArray arrayWithObjects:[UIColor orangeColor], [UIColor cyanColor], [UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];

    for (int i = 0; i < colors.count; i++) {
        CGRect frame;
        frame.origin.x = _scrollView.bounds.size.width * i;
        frame.origin.y = 0;
        frame.size = _scrollView.bounds.size;

        UIView *subview = [[UIView alloc] initWithFrame:frame];
        subview.backgroundColor = [colors objectAtIndex:i];
        [_scrollView addSubview:subview];

    }

    _scrollView.contentSize = CGSizeMake(_scrollView.bounds.size.width * colors.count, _scrollView.bounds.size.height);

次に、 didRotateFromInterfaceOrientationメソッドに追加しました。

_scrollView.contentSize = CGSizeMake(_scrollView.bounds.size.width * colors.count, _scrollView.bounds.size.height);

for (int i= 0; i< colors.count; i++)
{
    CGRect frame;
    frame.origin.x = _scrollView.bounds.size.width * i;
    frame.origin.y = 0;
    frame.size = _scrollView.bounds.size;


    UIView *subview= [[_scrollView subviews] objectAtIndex:i];

    subview.frame= frame;
}

これは機能しているようですが、デバイスの回転中にメインビューにクリッピングがあるようです。

回転時に何が起こるかのスクリーンショットを次に示します。 ここに画像の説明を入力

回転させた後にサイズを変えたせいだと思って、willRotateToInterfaceOrientationメソッドで処理しようとしたのですが、間違った結果になってしまいました…

  • これを間違って処理していますか?
  • 正しいアプローチは何でしょうか?

ティア!S.

これを間違って処理していますか?

4

1 に答える 1

0

境界を変更するコードは に配置する必要がありますが、willRotateToInterfaceOrientation( を使用して)アニメーション ブロックに[UIView animateWithDuration:0.4 animations:...]配置して、遷移が即時ではなくスムーズになるようにします。

追加の注意として、willRotateToInterfaceOrientation 内では、親ビューはまだサイズ変更されていないため、その境界に依存してビューの最終的な位置を計算することはできず、手動で行う必要があります。

于 2012-05-17T08:23:46.857 に答える