iphone - 在用户操作时旋转 UIViewController

标签 iphone ios uiviewcontroller uiinterfaceorientation

我拥有的:

我有一个支持纵向和横向的 View Controller 。当处于横向时,我会显示纵向内容的过滤器 View 。

我需要做什么:

当用户在横向 View 中选择过滤器时,我想强制将设备旋转回纵向。

我做了一些谷歌搜索并发现

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

这是一个私有(private) API,我不想这样做。 (但这正是我所追求的)

简而言之 - 在用户操作时我想强制旋转设备。 我在文档中遗漏了什么吗?

任何想法都会很棒。 丹

最佳答案

这是从经验中学到的!在您的 viewDidLoad::

中执行此操作
UIViewController *vc = [[UIViewController alloc] init];
[self presentModalViewControllerAnimated:NO];
[self dismissModalViewControllerAnimated:NO];

如果您仅对横向的 shouldAutorotateToInterfaceOrientation 返回 YES,它将强制横向。没有私有(private) API!

关于iphone - 在用户操作时旋转 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11884695/

相关文章:

iphone - 长按添加新 View 后如何保留触摸事件

ios - 如何在 Xcode 的不同 iPhone 尺寸类别中使用不同尺寸的图像

iphone - CFWriteStreamWrite/CFReadStreamWriter 容易超时吗?

objective-c - 后台任务似乎没有被取消/结束

ios - 如何更新 "Any"类型对象中的值

iphone - 如何知道 UIViewController View 在后台后何时显示?

iphone - 如何在不为 UIView 的 UIImageView 上画线?

ios - 尺寸等级 : starting with Compact Regular and moving to Any Any rather than vice versa?

iphone - 为什么我的 subview 无法根据设备方向正确居中?

iphone - 我的 UIViewController 的中心属性是 "lying"