xcode - 横向呈现ModalViewController

标签 xcode ipad uiviewcontroller orientation landscape

我已经搜索过这个论坛(和其他论坛),但尚未找到解决方案。 我有一个横向模式的应用程序。一切都很好,但是当我更改为另一个 View (使用 UITable)时,它处于纵向模式并且不会旋转。我已经尝试了一整天,但无法弄清楚。

@property (nonatomic, strong) IBOutlet UIView *aView;
@property (nonatomic, strong) IBOutlet UIViewController *aViewcontroller;
-----
aViewcontroller = [[UIViewController alloc] initWithNibName:@"ViewController" bundle:nil];
aViewcontroller.view = aView;
-----
[self presentModalViewController:aViewcontroller animated:YES];
//got my view in portrait orientation.

我的 .xib 文件中的 View 全部设置为方向:横向。 这应该很简单吧?

先谢谢了!

最佳答案

默认情况下,UIViewController 仅支持纵向。为了支持其他方向,您需要创建新的自定义 View Controller 来支持您需要的方向。

步骤:

创建新的自定义 View Controller ViewControllerLandscape

然后将其导入到您的 mainn View Controller

#import "ViewControllerLandscape.h"

更改您的代码:

aViewcontroller = [[ViewControllerLandscape alloc] initWithNibName:@"ViewController" bundle:nil];
aViewcontroller.view = aView;
[self presentModalViewController:aViewcontroller animated:YES];

在您的ViewControllerLandscape中添加方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
      (interfaceOrientation == UIInterfaceOrientationLandscapeRight))  {   
       return YES;
    }
    return NO;
}

关于xcode - 横向呈现ModalViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11670539/

相关文章:

ios - 是什么导致基本本地化创建重复的 Storyboard文件?

html - 在javascript中更改背景位置会弄乱显示

ios - Swift Popup 如何将值传递给 PopupViewController

ios - UINavigationBar 更改字体

ios - Jazzy 无法按预期生成快速文档

ios - Xcode 8 Beta 中的约束和大小类

ios - 在 iOS5 中使用 UISegmentedControl 切换 ViewController

iOS:NSObject 调用并检测哪个 UIVIewController 进行了调用

c++ - boost::filesystem 的段错误

javascript - iDevice浏览器,更改选择菜单内容