0

私が望むように機能していたいくつかのテキストビューを含むビューがありました。横向きでも縦向きでも、同じ右マージンに拡張されます。

最近、通常のビューをスクロールビューに変更しようとしました。ただし、これらのテキスト ビューを以前のように拡大することはできませんでした。横向きモードでは、縦向きの電話と同じ幅で、すべてが左側に収まります。

ここにいくつかのコードがあります。

- (void)viewDidLoad {
    CGSize screen = [self handleScreenOrientation];
    [(UIScrollView *)self.view setContentSize:CGSizeMake(screen.width, screen.height)];
}

- (CGSize)handleScreenOrientation {
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    CGRect screenRect = [[UIScreen mainScreen] bounds];

    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown ) {
        return CGSizeMake(screenRect.size.width, screenRect.size.height);
    }
    else {
        return CGSizeMake(screenRect.size.height, screenRect.size.width);
    }
}

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    CGSize screen = [self handleScreenOrientation:toInterfaceOrientation];
    UIScrollView *scrollView = (UIScrollView *)self.view;
    scrollView.frame = CGRectMake(0, 0, screen.width, screen.height);
    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height);
    [scrollView setNeedsDisplay];
}

渡された向きを持つメソッド handleScreenOrientation は、パラメーターのないメソッドと同じですが、ステータス バーの現在の向きではなく、渡された向きを使用するだけです。

チェックしたところ、スクロールビューがサブビューの自動サイズ変更に設定されています。

どんなアイデアでも大歓迎です。ありがとう。

更新:追加しました

self.view.autoresizesSubviews = true;

for (UIView *view in self.view.subviews) {
    view.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth;
}

ビューにdidloadし、インターフェイスの向きに回転します。変化なし。

4

1 に答える 1