【问题标题】:Tabbar Nav app, allowing one view to rotate while others do notTabbar Nav 应用程序,允许一个视图旋转而其他视图不旋转
【发布时间】:2010-07-02 13:27:36
【问题描述】:

我有一个标签栏应用程序,其中我有 3 个不同的视图,每个视图都有自己的视图控制器。

在标签条码中我有这个,用于处理旋转。

#import "RotatingTabBarController.h"

@implementation RotatingTabBarController

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

      return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
 }
@end

然后在我想要根据设备方向旋转的第二个视图控制器中:

// Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

   return YES;
 }

对于其他两个我不想旋转的视图,我设置了这个方法。

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

问题:因此,当您旋转设备时,这在视图 1 和视图 3 中工作正常,它们保持在所需的纵向模式。当我在视图 2 中旋转到横向时,视图会按预期进行并旋转到横向。但是,当在视图 2 中处于横向模式时单击视图 1 或视图 3 选项卡时,视图 1 和视图 3 处于横向模式。

即使视图 2 旋转到横向,我也不知道如何强制它们纵向显示。

有人知道怎么做吗?

【问题讨论】:

    标签: iphone uitabbar autorotate multiple-views


    【解决方案1】:

    从 2008 年到现在,对此进行了广泛的讨论[1](请看几页的 cmets)- 总而言之,它看起来像

    application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
    

    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
    

    [application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];
    

    将让您强制它横向 - 当用户以编程方式返回您的横向视图时,您会希望这样做。

    [1]iPhone app in landscape mode, 2008 systems

    【讨论】:

    • 除了应用程序启动之外,任何时候都不应该真正使用它。在应用程序生命周期的中途强制状态栏方向是非常糟糕的,并且可能会产生意想不到的后果。
    • 有任何官方消息这么说吗?有些应用程序具有例如一个“视图模式”,在必要时切换方向,以及许多其他需要改变方向的情况。
    • “如果你的应用程序有可旋转的窗口内容,但是,你不应该使用这种方法任意设置状态栏方向” - developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-25
    • 2012-09-19
    • 2011-09-21
    • 1970-01-01
    相关资源
    最近更新 更多