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

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

问题描述

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

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从Landscape到Portrait的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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