Objective c 界面旋转上的iPad黑屏

Objective c 界面旋转上的iPad黑屏,objective-c,ipad,rotation,orientation,Objective C,Ipad,Rotation,Orientation,我有一个在故事板模式下创建的通用应用程序。它设置为自动旋转到当前方向。当iPad旋转时,它应该经过以下代码,但我得到的只是一个黑屏 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [super willRotateToInterfaceOrientation:toInterfaceOrientati

我有一个在故事板模式下创建的通用应用程序。它设置为自动旋转到当前方向。当iPad旋转时,它应该经过以下代码,但我得到的只是一个黑屏

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
    self.view = landscape;
    self.view.transform = CGAffineTransformMakeRotation(deg2rad*(90));
    self.view.bounds = CGRectMake(0.0, 0.0, 1024.0, 748.0);
} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
    self.view = landscape;
    self.view.transform = CGAffineTransformMakeRotation(deg2rad*(-90));
    self.view.bounds = CGRectMake(0.0, 0.0, 1024.0, 748.0);
} else {
    self.view = portrait;
    self.view.transform = CGAffineTransformMakeRotation(0);
    self.view.bounds = CGRectMake(0.0, 0.0, 768.0, 1004.0);
}
} else {

}
}
为什么所有这些问题都出现在这里?发生了什么事?我该如何解决

编辑:调试控制台结果:
po[横向递归描述]
我的回答是:无法打印Nil对象的描述


编辑:即使UIViews链接到其门店,仍会显示黑屏。

您的
横向
变量为零。这就是为什么你会得到一个黑屏。您需要将其设置为UIView。

在方法中设置断点。当遇到断点时,在调试器控制台中运行此命令:
po[scape recursiveDescription]
。将输出粘贴到问题中。然后运行以下命令:
po[肖像递归描述]
。将输出粘贴到您的问题中。@robmayoff当我在(gdb)之后键入此:po[scape recursiveDescription]时,我的回答是:无法打印Nil对象的描述。我在第二个条件语句之后的每一行都尝试过它。我不确定我是否做得对,因为我不熟悉调试控制台。使用IBOutlets和@Prop/Synth,我设置了一个UIView作为横向出口,但它仍然会显示一个黑屏。当调用
willRotateToInterfaceOrientation:
时,您是否验证了
横向
不是零,使用调试器或
NSLog
?我检查了上面代码段中的每一行,并在调试器中输入了该命令,得到了相同的结果。我认为这是视图之间通信的问题,我制作了一个测试应用程序,同样的事情也发生了。如果它告诉你“不能打印一个NIL对象的描述”,那么
scape
就是NIL。你需要想想为什么可能是零。可能您没有从nib加载此视图控制器。也许您更改了
横向
的值。我理解您的意思,但我使用的是故事板(抱歉没有澄清),这可能是限制吗?在情节提要模式下没有自定义景观视图?