【问题标题】:presentModalViewController in landscape横向的presentModalViewController
【发布时间】:2012-07-25 02:42:37
【问题描述】:

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

先谢谢了!

【问题讨论】:

    标签: xcode ipad uiviewcontroller orientation landscape


    【解决方案1】:

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

    步骤:

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

    然后将其导入您的主视图控制器

    #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;
    }
    

    【讨论】:

    • 你需要把它放在aViewcontroller.m中
    • 还将它添加到您的主视图控制器 + 在 Targets->Summary set Supported Device Orientations
    • 我还没有 aViewController.m 文件。 \n 我在 ViewController.h & m 中创建视图控制器...这不是正确的方法吗?
    • 我遇到了你的问题。您应该创建 customViewController 并添加我在这个控制器的答案中编写的代码。我修改了答案
    • 超级!做了一个新的测试项目,它工作正常。如果我实施这个应该可以工作。很感谢。感谢您的清晰解释,我明白了。
    猜你喜欢
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-20
    相关资源
    最近更新 更多