【问题标题】:Device orientation at launch启动时的设备方向
【发布时间】:2011-09-28 23:07:08
【问题描述】:

我已阅读有关此主题的所有帖子,但仍然无法弄清楚这一点。

我在applicationDidFinishLaunching 的窗口中添加了一个 VC。 VC 包含一个 UIImageView。

我想根据设备方向设置 UIImageView 的图像,但是statusBarOrientationdeviceOrientationinterfaceOrientation,我检查的所有内容都返回纵向。

一定是我缺少一些简单的东西。

感谢您的帮助。

【问题讨论】:

    标签: cocoa-touch ipad uikit


    【解决方案1】:

    您是否启用了 Info.plist 中的其他方向?在 Xcode 4 的项目编辑器中有一个图形编辑器。

    【讨论】:

      【解决方案2】:

      有时(不确定这是在每种情况下,还是只是模拟器),应用程序会以一个方向启动,然后立即旋转到另一个方向以匹配设备方向。

      我建议实现-[UIViewController willRotateToInterfaceOrientation:duration:] 来设置您的图像,之后应该立即调用它。

      【讨论】:

      • 嗯... iPad 以正确的方向启动,并显示正确的默认图像,因此不会调用它。我需要检测当前方向的东西,而不是改变。
      【解决方案3】:

      嗯.. 似乎有几个问题。 1) 模拟器不会像预期的那样始终如一地生成方向(或方向变化)数据。此外,2)在启动时,设备可能(或可能不会)及时发送 statusBarOrientation 信息以读取该信息。所以,我在应用委托的 didFinishLaunching 方法中做到了这一点。

      // add the splash IV to the window per the current orientation, then animate it away
      [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
      if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait){
      self.theSplashIV.image = [UIImage imageNamed:@"Default-Portrait~ipad.png"];
          self.theSplashIV.frame = CGRectMake(0, 20, 768, 1004);
      }
      else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown){
          self.theSplashIV.image = [UIImage imageNamed:@"Default-Portrait~ipad.png"];
          self.theSplashIV.transform = CGAffineTransformMakeRotation(M_PI);
          self.theSplashIV.frame = CGRectMake(0, 0, 768, 1004);
      }
      else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft){
          self.theSplashIV.image = [UIImage imageNamed:@"Default-Landscape~ipad.png"];
          self.theSplashIV.transform = CGAffineTransformMakeRotation(M_PI / 2);
          self.theSplashIV.frame = CGRectMake(0, 0, 748, 1024);
      }
      else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight){
          self.theSplashIV.image = [UIImage imageNamed:@"Default-Landscape~ipad.png"];
          self.theSplashIV.transform = CGAffineTransformMakeRotation(M_PI / -2);
          self.theSplashIV.frame = CGRectMake(20, 0, 748, 1024);
      }
      [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
      

      然后,我延迟了启动水花 IV 的动画。 不是很优雅,但很有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-26
        • 1970-01-01
        • 1970-01-01
        • 2020-12-04
        相关资源
        最近更新 更多