objective-c - 呈现强制横向的模态视图 Controller

标签 objective-c ios cocoa-touch uiviewcontroller modalviewcontroller

我正在从 TableView 中呈现一个像这样的模态视图 Controller (忽略内存泄漏,只是测试..):

[self presentModalViewController:[[SignatureVC alloc] init] animated:YES];

在我的 SignatureVC 中,我实现了这个:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

我希望 SignatureVC 仅处于横向模式。但是,在呈现模态视图 Controller 之后,方向不会改变。 我究竟做错了什么?谢谢。

最佳答案

-shouldAutorotateToInterfaceOrientation: 方法不会旋转界面方向。如果设备方向旋转,它仅允许界面方向旋转。

如果模态视图在设备处于纵向时出现,则它将处于纵向。但是,一旦您旋转到 landscapeLeft,它将使用此代码保持锁定在该方向。

要强制界面旋转,您可以使用

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;

关于objective-c - 呈现强制横向的模态视图 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6560360/

相关文章:

ios - 将 UITableViewCell 的背景颜色设置为图案图像

ios - 如何删除 canDisplayAdBanner 创建的空白区域?

ios - 使用 Facebook iOS SDK 发布运行操作

ios - 从强制退出启动应用程序时检测可操作的通知按钮 - Swift

ios - 如何使用 GIT LFS 跟踪 iOS 框架?

ios - 在iOS 8.1中,当我在UITableView处于编辑模式下单击行的删除按钮时,该行及其上方的内容显示不正确

iphone - 如何通过单击激活 CCMenuItem 并移动 CCSprite

ios - 如何使用 fetchAssests 按添加日期的顺序获取 PHAssets

objective-c - 比较 NSString 和有关 NSNumber 的警告

iphone - 如何选择 UIWebView 中显示的 PDF 中的文本?