0

アプリで横向きと縦向きをサポートする必要があり、単一のUIViewを使用することに挑戦します。

最初にアプリケーションをシミュレートしたとき、問題なく結果が表示されます。ただし、向きを横向きに変更すると問題が発生します。

初めてアプリケーションを縦向きで実行するとき: ここに画像の説明を入力してください

向きを横向きに変更する場合: ここに画像の説明を入力してください [情報]タブの近くの左下隅に注目してください。

向きを縦向きに戻すと、 ここに画像の説明を入力してください 悪化します。

私が使用しているコード、

- (void)updateLayoutForNewOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    CGFloat height = CGRectGetHeight([[UIScreen mainScreen] bounds]);
    CGFloat width = CGRectGetWidth([[UIScreen mainScreen] bounds]);

    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
        NSLog(@"Portrait");
        [self iPhoneUserInterfacePortrait:width height:height];
    }

    else if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
        NSLog(@"Landscape");
        [self iPhoneUserInterfaceLandscape:width height:height];
    }
}

- (void)iPhoneUserInterfacePortrait:(CGFloat)width height:(CGFloat)height
{
    UITextView *descriptionTextView = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, width - 100.0, height - 300.0)];

    [self makeBorder:descriptionTextView];
    [self setInformation:descriptionTextView];
    [self.view addSubview:descriptionTextView];
}

- (void)iPhoneUserInterfaceLandscape:(CGFloat)width height:(CGFloat)height
{
    UITextView *descriptionTextView = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, width + 230, height - 368.0)];

    [self makeBorder:descriptionTextView];
    [self setInformation:descriptionTextView];
    [self.view addSubview:descriptionTextView];
}

- (void)makeBorder:(UITextView *)descriptionTextView
{
    descriptionTextView.layer.borderWidth = 3.0;
    descriptionTextView.layer.cornerRadius = 15.0;
    descriptionTextView.layer.borderColor = [[UIColor grayColor] CGColor];

    [self.view addSubview:descriptionTextView];
}
4

1 に答える 1

1

1つだけが必要なときに、複数のビューを追加しています。

[self.view addSubview:descriptionTextView];

この行をdescriptionTextView削除するには、ViewControllerサブクラスにフィールドを追加し、から追加/削除せずにそのテキストビューのフレームを変更しますself.view。また、自動サイズ変更マスクを試して、実際に手動でフレームを変更せずに必要な結果が得られるかどうかを確認する必要があります。そして、その定数に注意する必要があります。3.5インチと4.0インチの両方のシミュレーターデバイスでアプリを試してください。

于 2013-02-27T12:10:34.213 に答える