在横向模式下启动 iPad 应用程序时,无法获得正确的边界。我在 Info.plist 文件中设置了正确的键,并且我的视图控制器在横向(当然还有纵向)中正确启动。

在我的 applicationDidFinishLaunching: 方法我在 3 秒延迟后调用一个选择器,该方法调用 [[UIScreen mainScreen] applicationFrame], ,但它返回给我一个肖像框(即高度>宽度)。

有谁知道如何解决这一问题?对我来说,它闻起来像一个错误(如果是这样,我会归档雷达),但如果它是预期的行为,它记录在哪里?

有帮助吗?

解决方案

当您手握ipad公司在横向方向和启动一个应用程序,该视图控制器最初认为界限为纵向视图(即使取向报告横向)。然后,视图控制器将收到一条消息旋转到横向才会出现。

其他提示

我从不依靠[[UIScreen mainScreen] applicationFrame],特别是在应用程序启动。

当在代码中创建视图,使用上海华来设置帧。

如果您使用的是与“模拟界面元素”,他们将是正确的大小和一切xibs会是不错的。

<强>基于UINavigationController的应用

在基于应用程序的UINavigationController的情况下,直接从self.navigationController.view抓住框架,也不尝试使用[self loadView]self.view.superview。 UINavigationController的采用了“隐藏”子视图这样做的工作 - 所以直接上海华将无法正常工作

UINavigationController的是特殊的,因为应用程序启动时,导航控制器重新调整你的意见loadView被调用后。当在自动踢你最终在屏幕底部的小幅度。

<强>为什么不UIScreen

[[UIScreen mainScreen] applicationFrame]不(尤其是在横向应用启动)可靠地工作。我的经验是,视图 - 控制的interfaceOrientation财产将不匹配applicationFrame方向。

CGRect bounds = [[UIScreen mainScreen] bounds]; // portrait bounds
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
    bounds.size = CGSizeMake(bounds.size.height, bounds.size.width);
}

这是我得到正确的CGRect的方式,当视图控制器是对景观:

CGRect landscapeBounds;
if (self.view.frame.size.width < self.view.frame.size.height)
    landscapeBounds = CGRectMake(self.view.frame.origin.y, self.view.frame.origin.x, self.view.frame.size.height, self.view.frame.size.width);
else
    landscapeBounds = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);

这是有意设计的。你应该询问你的上海华盈的规模和调整是必要的。

[[UIScreen mainScreen] applicationFrame]将总是返回,即使应用程序是在横向模式下的纵向矩形。这涉及到一个事实,即UIWindow从不的实际转动,但只是改变了,而不是变换rootViewController.view的。

要确保,你可以打印根查看对象在纵向和横向模式,你会看到这样的内容:

人像:

<UIView: 0x96290e0; frame = (0 20; 768 1004); ...

风景:

<UIView: 0x96290e0; frame = (0 20; 768 1004); transform = [0, 1, -1, 0, 0, 0]; ...

因此,根据 Apple 的指南,添加启动图像并为其添加后缀 -568h。

我不明白为什么任何有头脑的人都会让系统设置依赖于图形;但我刚刚测试过并且有效。

这是快速搜索后教我的地方 我没有在上面看到这个答案,认为它对某人有用。

S

我驳回视图与dismissViewControllerAnimated科尔多瓦插件当钻进同样的问题。 我修改singingAtom代码viewWillAppear中方法在MainViewController,这得到了驳回模态的视图后调整大小:

- (void)viewWillAppear:(BOOL)animated
    {
    CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
    UIDeviceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (UIDeviceOrientationLandscapeLeft == orientation || 
        UIDeviceOrientationLandscapeRight == orientation)
            {
            if (appFrame.size.width < appFrame.size.height)
                {
                appFrame = CGRectMake(appFrame.origin.y, appFrame.origin.x, appFrame.size.height, appFrame.size.width);
                }
        }
    self.view.frame = appFrame;
    [super viewWillAppear:animated];
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top