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.frameview.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 回答
0

您看到的是屏幕顶部的状态栏。是20分。

由于您使用的是自动布局,因此它会自动布局您的视图以使其适合状态栏未覆盖的屏幕部分。

于 2013-04-27T21:07:13.697 回答