风景xib显示为肖像

我有一个视图控制器和单独的笔尖和风景的笔尖文件。 在旋转时,我加载相应的笔尖。 方法

shouldAutorotateToInterfaceOrientation and willRotateToInterfaceOrientation 

被叫,笔尖确实改变了。

问题:

 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中performance为景观。 (我不认为这将是可能的创build一个旋转的button,如果该视图是肖像。)除了这两个笔尖,我有一个mainwindow.xib ,其中包含应用程序委托,窗口和视图控制器对象。

编辑:我意识到,实际上是旋转,当他们应该“熬夜”。 这就像有一个额外的转变。 当我将手机向右旋转90°时,风景xib显示向右旋转90°。 当我将手机向右旋转90°时,肖像xib将显示为倒置。 状态栏始终正确显示在顶部。

编辑2:使用

 self.view.transform = CGAffineTransformMakeRotation((M_PI * (90) / 180.0)); 

在willRotateToInterfaceOrientation我可以旋转视图横向左(和我想要的任何方向),所以我可以使用它作为解决方法。 但是,我有其他项目,视图自动旋转,并不需要使用CGAffineTransformMakeRotation。 这就像是在阻止自动旋转。

你是否添加从nib作为子view加载view ? 如果只有状态栏正在旋转,这意味着您释放视图并添加新视图时,您的上一个视图被挂起。您可以告诉您如何将从xib加载的视图添加到SuperView。

请确保在加载其他视图时正确地释放了以前的视图,将NSLOG放入NSLOG的dealloc中,并检查视图是否完全释放。

我只做了类似于这个,而不是单独制作一个笔尖文件我只是添加了两个子视图的主要笔尖作为prtraitView和横向视图

并按如下方式切换

在viewDidAppear方法中

 -(void)viewDidAppear:(BOOL)animated{ if(UIDeviceOrientationIsPortrait(self.interfaceOrientation)) { self.portraitVIew.frame=self.view.bounds; self.portraitVIew.frame=self.view.frame; [self.view addSubview:self.portraitVIew]; }else{ self.landscapeView.frame=self.view.frame; [self.view addSubview:self.landscapeView]; } self.view.autoresizesSubviews = YES; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChangeNotification:) name:UIDeviceOrientationDidChangeNotification object:nil]; } 

然后执行deviceOrientationDidChangeNotification如下

 - (void)deviceOrientationDidChangeNotification:(NSNotification*)note { if ([[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad) { }else{ UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; if(UIDeviceOrientationIsLandscape(self.interfaceOrientation)) { self.landscapeView.hidden=NO; self.landscapeView.frame=self.view.frame; [self.portraitVIew removeFromSuperview]; [self.view addSubview:self.landscapeView]; }else { self.landscapeView.hidden=YES; self.portraitVIew.frame=self.view.frame; NSLog(@"Portrait"); [self.view addSubview:self.portraitVIew]; } } } 

它对我来说非常好