我的RootViewController中有一个按钮.... 当我点击这个按钮时,它将导航到其他一些ViewController。 但我希望当我点击按钮时,otherViewController的Orientation应该是Landscape &安培;当我从这个页面(otherViewController)回来时,我应该再次获得肖像模式。
非常感谢您的帮助。 Plz帮我解决了Iphone新问题,因此无法解决这个问题。
答案 0 :(得分:1)
iOS 6中的注意事项shouldAutorotateToInterfaceOrientation
为deprecated。相反,您应该使用supportedInterfaceOrientations
并返回UIInterfaceOrientationMask
。
例如:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
以下是您可能返回的所有UIInterfaceOrientationMask选项:
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskPortraitUpsideDown
您还应该考虑preferredInterfaceOrientationForPresentation
。
答案 1 :(得分:0)
通常,当用户旋转设备时,方向应仅从纵向更改为横向(反之亦然)。
但是,如果您希望RootViewController始终以纵向方式呈现其视图,而您的OtherViewController始终以横向方式显示itvs视图,那么这很容易。
在RootViewController的.h:
中- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
在你的OtherViewController的.h:
中- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
虽然这可能会更好,因为它允许横向左转和右转右转:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
答案 2 :(得分:0)
我知道这一点的唯一方法是通过模态呈现otherViewController。
请在此处查看我的回答:UIViewController loads rotated to landscape but only supports portrait
答案 3 :(得分:-1)
也许有帮助。
在新视图控制器的viewWillAppear中添加
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscape]
并在你的根viewController的viewWillAppear中添加
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
它会引起警告但是有效。