我有一个视图控制器,还有独立的横屏和竖屏nib文件。在旋转时,我会加载相应的nib文件。相应的方法如下:
shouldAutorotateToInterfaceOrientation and willRotateToInterfaceOrientation
get called and the nib does change.
The problem:
the landscape nib does not appear as landscape, but portrait! The status bar is
correctly rotated and appears on the top:
(Sorry, couldn't paste the image, because my account is new. The screenshot is in
landscape, with a landscape status bar, but a landscape view shown as portrait.)
有人可能认为问题在于未在IB模拟度量中将方向设置为横向,但我已经这样做了,在IB中该视图显示为横向。(如果视图是纵向的,甚至不可能创建旋转的按钮。)除了这两个nib文件外,我还有一个 mainwindow.xib ,其中包含应用程序委托、窗口和视图控制器对象。
编辑:我意识到视图实际上正在旋转,而它们应该“保持上升”。就像有一个额外的变换一样。当我将手机向右旋转90°时,横向xib显示为向右旋转90°。当我再次将手机向右旋转90°时,纵向xib显示为倒置。状态栏始终正确地显示在顶部。
编辑2:使用
self.view.transform = CGAffineTransformMakeRotation((M_PI * (90) / 180.0));
在willRotateToInterfaceOrientation方法中,我可以将视图旋转到左横屏(以及任何我想要的方向),因此我可以将其用作解决方法。但是,我还有其他项目,其中视图会自动旋转,不需要使用CGAffineTransformMakeRotation。就好像这里有什么东西阻止了自动旋转。
shouldAutorotateToInterfaceOrientation
方法中,返回YES;
。此外,在您的项目 Targets->Summary 中,请确保您已设置支持的方向。 - tipycalFlow