【问题标题】:iPhone - adding views and landscape orientationiPhone - 添加视图和横向
【发布时间】:2010-06-16 17:26:48
【问题描述】:

我遇到了 Cocoa 触控和横向方向的问题。

我从 .xib 实例化我的视图;我在我的视图控制器中添加了

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

只允许横向。

这适用于我添加的第一个视图。如果我添加第二个视图,但它会再次旋转,就像横向视图以纵向模式显示(逆时针旋转 90 度)。

我真的不知道发生了什么,也找不到解决方法。我什至试图通过两次添加我的视图来了解正在发生的事情:

MainMenuViewController* controller = [[MainMenuViewController alloc] initWithNibName:@"MainMenu" bundle:nil];
[window addSubview: controller.view];

MainMenuViewController* controller2 = [[MainMenuViewController alloc] initWithNibName:@"MainMenu" bundle:nil];
[window addSubview: controller2.view];


[window makeKeyAndVisible];

控制器的视图正确显示,而控制器2的视图旋转了90度。有谁知道这是怎么发生的?感谢您的帮助。

【问题讨论】:

    标签: iphone


    【解决方案1】:

    也许你应该放

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

    也在你的 mainMenuViewController 中

    【讨论】:

    • 这正是我所做的。问题是,该方向首先适用于第一个实例。第二个实例旋转了 90 度。我现在通过在我的窗口和我通过代码更改的自定义视图之间附加一个视图来解决问题。这似乎有效。尽管如此,这是一种我不明白的奇怪行为。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    • 2010-12-30
    • 1970-01-01
    • 1970-01-01
    • 2012-02-05
    • 2011-05-12
    • 1970-01-01
    相关资源
    最近更新 更多