【问题标题】:iPhone SDK: Forcing landscape mode for a single part of an appiPhone SDK:为应用程序的单个部分强制横向模式
【发布时间】:2010-01-19 16:50:45
【问题描述】:

又一个横向模式问题。

我们都见过

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

废话。我无法让它在模拟器或设备上运行。

我得到的是这样的:

http://i47.tinypic.com/zl9egh.png

当我真的想要这个时:

http://i45.tinypic.com/xms6cm.png

您可能会说,它正在翻转手机,但它没有意识到它已被翻转。

我见过隐藏的方法

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

但我需要这个应用在应用商店上架,我不知道他们是否会对此进行打击。

有没有人知道如何让这该死的东西自己理顺?

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    理想情况下,您的视图控制器应该实现:

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

    那么该视图控制器唯一允许的方向是横向方向之一。

    除非您有一个使用标签栏控制器的非常复杂的视图层次结构,否则这应该会导致视图在被推送时旋转。

    如果不行你可以试试:

    [[UIDevice currentDevice] performSelector:
                                   @selector(setOrientation:) 
                               withObject:(id)UIInterfaceOrientationLandscapeRight];
    

    我在 AppStore 中有一个使用此代码的应用程序,因为在我的情况下,我确实有一个复杂的视图层次结构,这使我只需要横向的视图无法工作。

    【讨论】:

    • 这确实解决了一个错误地翻转回纵向视图的问题。但是我的主要问题是初始负载。当它被推动时,它会以纵向模式结束。我将状态栏代码放在目标视图控制器的 viewDidLoad 中......我应该把它放在其他地方吗?
    【解决方案2】:

    如果您想旋转应用程序的单个部分,您可以使用 UIView 的 CGAffineTransform 变换属性。例如,检查这个线程:

    How do I apply a perspective transform to a UIView?

    【讨论】:

      猜你喜欢
      • 2010-10-13
      • 1970-01-01
      • 1970-01-01
      • 2014-04-28
      • 2010-10-13
      • 2013-05-24
      • 1970-01-01
      • 1970-01-01
      • 2010-09-05
      相关资源
      最近更新 更多