问题 pushViewController 从横向到纵向 [英] Problem pushViewController from Landscape to Portrait

查看:19
本文介绍了问题 pushViewController 从横向到纵向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从支持横向(在横向模式下)的视图控制器转变为明确不(也不应该)支持横向的视图控制器.我这样做如下:

I am trying to go from a viewcontroller that supports landscape (while in landscape mode), to one that explicitly doesn't (and shouldn't) support landscape. I'm doing this as follows:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

理想情况下,我希望我推入堆栈的新 viewController 最初以纵向而不是横向开始.奇怪的是,即使实施了这种方法,它还是从 Landscape 开始.

Ideally I want the new viewController that i'm pushing onto the stack to start off initially in portrait, not landscape. Strangely even with this method implemented, it starts off in Landscape.

我唯一的猜测是 Apple 不希望用户从横向切换到纵向(尽管允许我们从横向切换回以前的纵向控制器).

My only guess is that Apple doesn't want a user transitioning from landscape to portrait (despite allowing us to go from landscape, back to a previous controller that is in portrait).

任何见解和/或帮助将不胜感激.

Any insights and/or help would be much appreciated.

推荐答案

我找到了一种强制肖像的方法.这有点黑客,但就是这样.在要强制纵向的 viewController 的 -(void)viewDidLoad 中,执行以下操作:

I found a way to force portrait. It's a bit a hack, but here it is. In the -(void)viewDidLoad of the viewController that you want to force portrait for do the following:

UIViewController *viewController = [[UIViewController alloc] init];
[self presentModalViewController:viewController animated:NO];
[self dismissModalViewControllerAnimated:NO];
[viewController release];

这基本上通过呈现控制器(默认情况下仅支持纵向)来强制纵向.

This basically forces portrait, by presenting a controller (which only supports portrait by default).

这篇关于问题 pushViewController 从横向到纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆