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

我们有UIWindow代码已经工作了多年,build立了一个“拦截”屏幕。 我们最近注意到,在iOS 8.3 iPad上,阻挡器以横向显示时偏移了256个像素。 有几个怪事:

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

2)如果拦截器是纵向显示的,那就好了

3)如果拦截器显示为纵向,然后旋转到风景,那就没问题了。

4)间距为256像素,即宽度和高度的差值,即1024 – 768 = 256。

我们最近更新到Xcode 6,所以这可能是一个因素,以及…

通过使用默认的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]; } 

如果你在模拟器上运行这个代码,并点击“+”button,你会得到:

在这里输入图像说明

这是我们所期望的。

但是,在我们的8.3 iPad设备上运行的这个相同的代码给了我们:

在这里输入图像说明

任何想法,为什么模拟器工作和设备不? build议? 其他的事情要尝试吗?

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

这是我们使用的修复:

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

我们也能够删除旋转调整代码,因为现在的视图控制器pipe理它适合我们(至less在iOS 8和更高版本)。 这里是我们现在使用的代码:(当屏幕旋转时调用)

  - (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; } 

您明确地将阻挡者的框架设置为纵向尺寸。 只有当设备旋转时才会改变。

相反,当阻塞程序正在创build时,尝试从显示屏获取大小到当前窗口。