【问题标题】:identifying the device for iPad iOS 4.2识别 iPad iOS 4.2 的设备
【发布时间】:2010-11-30 03:01:14
【问题描述】:

我知道 iOS 4.2 也适用于 iPad。下面的代码是我们都用来识别设备的标准模式。 4.2 iPad 将如何改变。我应该更改代码以考虑设备类型而不是版本吗?

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
    CGRect frame = [[UIScreen mainScreen] bounds];
    self.view.frame = frame;
#else
    CGRect frame = [self.view bounds];
#endif

【问题讨论】:

    标签: iphone ipad ios-4.2


    【解决方案1】:

    更好的方法是 [[UIDevice currentDevice] userInterfaceIdiom]

    首先检查 currentDevice 是否响应了该选择器。如果不是,那么它是运行 iOS 3.1.x 或更早版本的 iPhone/iPod。

    如果它确实响应了该选择器,那么您可以检查 UIUserInterfaceIdiomPhone 或 UIUserInterfaceIdiomPad 的结果。

    【讨论】:

      【解决方案2】:

      你也可以试试这个:

      #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
      
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
       {
           // type you code for iPad
       } else {
           // type you code for iPhone
       }
      
      #endif
      

      【讨论】:

        【解决方案3】:

        相应地检查设备版本和代码

        float version = [[[UIDevice currentDevice] systemVersion] floatValue];
            if (version == 4.2)
            {
                CGRect frame = [[UIScreen mainScreen] bounds];
            self.view.frame = frame;
        
            }
        else
            self.view.frame = frame;
        

        使用此代码可能会对您有所帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-01-04
          • 2018-11-09
          • 2013-10-11
          • 1970-01-01
          • 1970-01-01
          • 2011-11-11
          相关资源
          最近更新 更多