iOS 8.3上的自定义UIWindow iPad可在模拟器上运行,但不适用于设备 [英] Custom UIWindow on iOS 8.3 iPad works on simulator but not device

查看:124
本文介绍了iOS 8.3上的自定义UIWindow iPad可在模拟器上运行,但不适用于设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有UIWindow代码已经工作了多年,以建立一个阻止屏幕。我们最近注意到,在阻止程序以横向显示时,在iOS 8.3 iPad上,阻挡程序偏移256像素。奇怪的是:

We have UIWindow code that has worked for years to put up a "blocker" screen. 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. There are few oddities:

1)这不会发生在模拟器上,只会发生在设备上

1) This does not happen on the simulator, only the device

2)如果阻挡者以纵向显示,那就没问题了

2) If the blocker is shown in portrait it is fine

3)如果阻挡者以纵向显示然后旋转到横向,那就没问题了。

3) If the blocker is shown in portrait and then rotated to landscape it is fine.

4)间隙是256像素,这是宽度和高度之间的差异,即1024 - 768 = 256。

4) The gap is 256 pixels, which is the difference between the width and the height, i.e., 1024 - 768 = 256.

我们最近更新到Xcode 6,所以这也是一个因素...

We've recently updated to Xcode 6, so this could be a factor as well...

使用默认的Xcode Master Detail项目可以轻松复制此问题对insertNewObject方法进行一些小的更改,如下所示:

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:

    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:

这是我们所期望的。

然而,这个完全相同的代码,正在运行在我们的8.3 iPad设备上给我们:

However, this same exact code, running on our 8.3 iPad device gives us:

有关模拟器工作原理和设备没有的任何想法?建议?其他要尝试的事情?

Any ideas of why the simulator works and the device doesn't? Suggestions? Other things to try?

[更新] 我们只找到一个设备,这是一个问题,iPad 2.我们还发现设置UIWindow上的rootViewController解决了这个问题。

[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.

推荐答案

以下是我们使用的修复:

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];

我们也能够删除旋转调整代码,因为现在视图控制器已经为我们正确管理了它(在至少适用于iOS 8及更高版本)。这是我们现在使用的代码:(在屏幕旋转时调用)

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). 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;
    }

这篇关于iOS 8.3上的自定义UIWindow iPad可在模拟器上运行,但不适用于设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆