Xcode – 使用XIBlocking除了一个视图以外的所有视图

我需要一些帮助。

我目前正在Xcode中的应用程序,我需要在纵向模式下locking所有视图,但我有第二个视图控制器,需要进入景观,因为我使用mediaplayer框架来显示video,需要在风景。

我一直在寻找这个,现在一个星期左右,仍然不能解决问题。

我会感谢提前的帮助。

这有两个方面。 1.如何locking每个视图控制器的方向。

但是,这一点不会旋转设备。 当你在肖像和下一个视图控制器被显示为横向,那么它仍然会呈现在肖像。 你可以把设备转到portait,conroller会相应的旋转。 一旦在风景中,它被固定在风景中,不能再旋转。 当你回到你的肖像控制器,它将呈现在横向…

所以,2.你需要旋转设备。

蓬1是容易的。

在修复肖像的所有控制器中执行此操作:

- (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } 

并为景观控制器实现这一点:

 - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } 

2.下一步你需要应用一个技巧。 您不能以编程方式打开设备。 唯一的方法是旋转状态栏。 之后,下一个模态(!)视图控制器以新方向呈现。 这对于在导航堆栈上推控制器不起作用。 诀窍是以模态方式呈现任何(空的)视图控制器,并立即将其删除。 现在,该设备被转动,你可以推视图控制器到堆栈。 这是我有一天使用的代码:

 // Fetch the status bar from the app and set its orientation as required. [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES]; // Create an empty view controller, present it modally and remove it directly afterwards UIViewController *mVC = [[UIViewController alloc] init]; [self presentModalViewController:mVC animated:NO]; [self dismissModalViewControllerAnimated:NO]; // Now the device is rotated to the desired orientation. Go from there. 

如果你正在使用模态视图控制器,那么它当然会更简单一些。