Xcode 景观中的presentModalViewController

Xcode 景观中的presentModalViewController,xcode,ipad,uiviewcontroller,orientation,landscape,Xcode,Ipad,Uiviewcontroller,Orientation,Landscape,我已经搜索了这个论坛(和其他论坛),但还没有找到解决方案。 我有一个应用程序在横向模式。一切都很好,但当我切换到另一个视图(使用UITable)时,它处于纵向模式,不会旋转。我已经试了一整天了,但还是想不出来 @property (nonatomic, strong) IBOutlet UIView *aView; @property (nonatomic, strong) IBOutlet UIViewController *aViewcontroller; ----- aViewcontro

我已经搜索了这个论坛(和其他论坛),但还没有找到解决方案。 我有一个应用程序在横向模式。一切都很好,但当我切换到另一个视图(使用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文件中的视图都设置为方向:横向。 这应该很简单,对吗


事先谢谢

默认情况下,UIViewController仅支持纵向。为了支持其他方向,需要创建新的自定义视图控制器,以支持所需的方向

步骤:

创建新的自定义视图控制器
ViewControllerLandscape

然后将其导入mainn view控制器

#import "ViewControllerLandscape.h"
更改您的代码:

aViewcontroller = [[ViewControllerLandscape alloc] initWithNibName:@"ViewController" bundle:nil];
aViewcontroller.view = aView;
[self presentModalViewController:aViewcontroller animated:YES];
视图Controllerlandscape
中添加以下方法:

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

您需要将其放入aViewcontroller.mAlso,然后将其添加到主视图控制器+在目标->摘要集支持的设备方向我没有aViewcontroller.m文件\n我在ViewController.h&m中创建ViewController。。。这不是正确的方法吗?我知道你的问题。您应该创建customViewController并将我在答案中编写的代码添加到此控制器。我同意了答案!做了一个新的测试项目,效果很好。如果我实施这一点,应该会起作用。非常感谢。谢谢你的解释,我明白了。