【问题标题】:What is the right way to determine portrait/landscape in and out of loading?确定加载和加载的纵向/横向的正确方法是什么?
【发布时间】:2013-09-30 15:55:47
【问题描述】:

我有几个实例的代码:

    if (!UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation))
    {
        backgroundImage = [UIImage imageNamed:@"Background-Default-Portrait.png"];
    }
    else
    {
        backgroundImage = [UIImage imageNamed:@"Background-Default-Landscape.png"];
    }

注意!在 UIInterfaceOrientationIsPortrait() 前面。我发现当应用程序第一次初始化时,它可以与 NOT 一起正常工作,并且无论应用程序是否第一次初始化,它都会拉出正确的背景,然后要么从那里旋转到使用错误的应用程序的横向和纵向。

我暂时绕过了这个问题,以牺牲 DRY 和良好的工程设计为代价,拥有两份代码副本,一份适合刚刚加载的应用,另一份以视图刷新为代价。但我想知道有什么更好的方法。我可以使条件更加巴洛克,但我发现 UIInterfaceOrientationIsPortrait() 在我从初始化代码中调用它时返回一种值样式,而在设备在横向和纵向之间旋转时调用另一种值。

【问题讨论】:

  • 您可以通过将所需方向作为“支持的界面方向”中的第 0 项来强制应用程序初始化的方式。也许这会有所帮助。

标签: iphone ios objective-c xcode ipad


【解决方案1】:

您始终可以使用UIViewControllerinterfaceOrientation 属性。

 BOOL isPortrait = UIDeviceOrientationIsPortrait(self.interfaceOrientation);

希望这会给您带来一致的结果。

【讨论】:

  • 其实是UIInterfaceOrientationIsPortrait(self.interfaceOrientation)
  • 在办公室,没有方便的 mac 来测试代码。请参阅已引用的此答案。 stackoverflow.com/questions/3600097/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-20
  • 1970-01-01
  • 2010-10-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多