简体   繁体   English

iOS 8.3 iPad上的自定义UIWindow可在模拟器上运行,但不能在设备上运行

[英]Custom UIWindow on iOS 8.3 iPad works on simulator but not device

We have UIWindow code that has worked for years to put up a "blocker" screen. 我们已经使用了多年的UIWindow代码来构建“阻止程序”屏幕。 We noticed recently that on an iOS 8.3 iPad the blocker is offset 256 pixels when the blocker is displayed in the landscape orientation. 我们最近注意到,在iOS 8.3 iPad上,当横向显示阻塞器时,阻塞器偏移256个像素。 There are few oddities: 奇怪之处很少:

1) This does not happen on the simulator, only the device 1)这不会在模拟器上发生,只会在设备上发生

2) If the blocker is shown in portrait it is fine 2)如果阻止器以纵向显示,则可以

3) If the blocker is shown in portrait and then rotated to landscape it is fine. 3)如果将阻止器显示为纵向,然后旋转至横向,则效果很好。

4) The gap is 256 pixels, which is the difference between the width and the height, ie, 1024 - 768 = 256. 4)间隙为256个像素,即宽度和高度之差,即1024-768 = 256。

We've recently updated to Xcode 6, so this could be a factor as well... 我们最近更新到了Xcode 6,因此这也可能是一个因素...

This problem can be easily replicated by using the default Xcode Master Detail project and making a few minor changes to the "insertNewObject" method as shown here: 通过使用默认的Xcode Master Detail项目并对“ insertNewObject”方法进行一些小的更改,可以很容易地复制此问题,如下所示:

    UIWindow *blocker;

    - (void)insertNewObject:(id)sender {


            blocker = [[UIWindow alloc] init];
            [blocker setBackgroundColor:[UIColor colorWithRed:.0 green:.0 blue:.0 alpha:.8]];
            [blocker makeKeyAndVisible];

            CGRect r = CGRectMake(0, 0, 768, 1024);
            [blocker setFrame:r];


    }

If you run this code on the simulator, and tap the "+" button you get: 如果您在模拟器上运行此代码,然后点击“ +”按钮,您将获得:

在此处输入图片说明

which is what we expect. 这就是我们的期望。

However, this same exact code, running on our 8.3 iPad device gives us: 但是,在我们的8.3 iPad设备上运行的相同的确切代码为我们提供了:

在此处输入图片说明

Any ideas of why the simulator works and the device doesn't? 关于模拟器为何起作用而设备不起作用的任何想法? Suggestions? 有什么建议吗? Other things to try? 还有其他尝试吗?

[UPDATE] We've only found one device where is this a problem, an iPad 2. We've also discovered that setting the rootViewController on the UIWindow "solves" the problem. [更新]我们只找到了一个有问题的设备iPad2。我们还发现,在UIWindow上设置rootViewController可以“解决”问题。

Here is the fix we used: 这是我们使用的修复程序:

blocker = [[UIWindow alloc] init];
[blocker setBackgroundColor:[UIColor colorWithRed:.0 green:.0 blue:.0 alpha:.8]];

UIViewController *blockerRoot = [UIViewController new];
blocker.rootViewController = blockerRoot;
CGRect r = [[UIScreen mainScreen] bounds];
[blocker setFrame:r];

[blocker makeKeyAndVisible];

We also were able to remove rotation adjustment code since now the view controller managed it properly for us (at least for iOS 8 and later). 我们还能够删除旋转调整代码,因为现在视图控制器已为我们正确管理了它(至少在iOS 8和更高版本中)。 Here's the code we now use for that: (called when the screen is rotated) 这是我们现在使用的代码:(旋转屏幕时调用)

    - (void)adjustForRotation
    {

        if ([UIUtil iOS8OrLater]){
        // iOS 8 handles this correctly, no need for adjustments...
            return;
        }

        UIInterfaceOrientation io = [[UIApplication sharedApplication] statusBarOrientation];
        if (UIInterfaceOrientationIsLandscape(io)){
            CGRect r = [[UIScreen mainScreen] bounds];
            CGFloat x = r.size.height / 2.0;
            CGFloat y = r.size.width / 2.0;
            self.center = CGPointMake(x, y);       
        }
        return;
    }

You are explicitly set the frame of the blocker to the portrait dimensions. 您已将阻隔器的框架显式设置为纵向尺寸。 It is only being changed when the device is rotated. 仅在旋转设备时才更改。

Instead, try getting the size from the display to current window when the blocker is being created. 相反,请在创建阻止程序时尝试将大小从显示器移至当前窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM