1

我正在编写一个设置为自动旋转的简单标签栏应用程序。我需要根据设备方向在屏幕上重新绘制一些对象。为此已打开通知并尝试获取屏幕的当前宽度。一切正常,但在横向模式下我得到纵向宽度,反之亦然!@?

AppDelegate didFinishLaunchingWithOptions:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

界面viewWillAppear:

NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
       selector:@selector(orientationChanged:)
           name:UIDeviceOrientationDidChangeNotification
         object:nil];

界面orientationChanged:

UIInterfaceOrientation orientation = [UIDevice currentDevice].orientation;

if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown)
{
    NSLog(@"Portrait Width: %f", self.view.frame.size.width);
}
else if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
{
    NSLog(@"Landscape Width: %f", self.view.frame.size.width);
}

在 iPad 上我得到:纵向宽度:1024 横向宽度:768

为什么我没有得到横向宽度:1024 和纵向宽度:768

这仅在应用程序启动时发生。一旦我点击另一个 tabitem,报告是正确的。

我应该在没有问题之前添加我用 stroyboard 编写的这个应用程序,但是由于 IOS 限制(部署目标),我将它重写为包含 4.0。这就是这个问题开始的地方。

上下搜索解决方案,但无法弄清楚。有什么想法吗?

4

0 回答 0