0

私はオートレイアウトを使用しています。

わかりました、私はコードに書きました:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    if (fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        DLog(@"rotated from landscape to portrait")
        DLog(@"self.view.frame: %@", NSStringFromCGRect(self.view.frame));

    }
    else if (fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        DLog(@"rotated from portrait to landscape")
        DLog(@"self.view.frame: %@", NSStringFromCGRect(self.view.frame));

    }
}

結果は次のとおりです。

DEBUG | -[LoginViewController didRotateFromInterfaceOrientation:] | rotated from portrait to landscape
DEBUG | -[LoginViewController didRotateFromInterfaceOrientation:] | self.view.frame: {{0, 0}, {748, 1024}}
DEBUG | -[LoginViewController didRotateFromInterfaceOrientation:] | rotated from landscape to portrait
DEBUG | -[LoginViewController didRotateFromInterfaceOrientation:] | self.view.frame: {{0, 20}, {768, 1004}}

フレームが変わらないのはなぜですか?ランドスケープで ((0, 0), (1024, 748)) に変化しないのはなぜですか!?

4

2 に答える 2

1

スーパービューの座標系のサイズであるフレームと、現在のビューの座標系内の寸法である境界を混同しています。スーパービューの座標系は変更されませんが、オフセットは変更される可能性があります (これがY、ステータス バーに対応する回転に基づいて原点が一貫して変更される理由です)。

view.frameの参照をに置き換えると、view.bounds期待どおりのサイズが表示されます。ディスプレイの選択を置き換えると、次のようになります。

2013-04-28 11:06:48.208 Autorotation[24308:c07] rotated from portrait to landscape
2013-04-28 11:06:48.209 Autorotation[24308:c07] self.view.bounds: {{0, 0}, {1024, 748}}
2013-04-28 11:06:49.351 Autorotation[24308:c07] rotated from landscape to portrait
2013-04-28 11:06:49.352 Autorotation[24308:c07] self.view.bounds: {{0, 0}, {768, 1004}}
2013-04-28 11:06:50.343 Autorotation[24308:c07] rotated from portrait to landscape
2013-04-28 11:06:50.343 Autorotation[24308:c07] self.view.bounds: {{0, 0}, {1024, 748}}
2013-04-28 11:06:52.173 Autorotation[24308:c07] rotated from landscape to portrait
2013-04-28 11:06:52.174 Autorotation[24308:c07] self.view.bounds: {{0, 0}, {768, 1004}}
于 2013-04-28T10:09:42.687 に答える