【问题标题】:How to : autorotation on iPad and portrait only on iPhone?如何:iPad 上的自动旋转和 iPhone 上的肖像?
【发布时间】:2013-07-16 04:07:48
【问题描述】:

您好,我刚刚开始 iPhone 编程。我在 Xcode 3.2 中为 iPad 和 iPhone 创建了一个通用应用程序,并且 evrerything 工作正常。但现在我想在该应用中实现以下功能:

它应该在 iPad 上支持自动旋转,在 iPhone 上只能是纵向的。

我不知道该怎么做。

我有一个 AppDelegate_iPad 委托文件, AppDelegate_iPhone 委托文件, 和共享选项卡下的视图控制器,由这两个代表共享。

任何想法如何实现该功能。任何帮助将不胜感激。

谢谢 维克

【问题讨论】:

    标签: iphone ipad xcode3.2 autorotate universal


    【解决方案1】:

    在您要实现此旋转行为的视图的视图控制器中,在shouldAutorotateToInterfaceOrientation 内进行检查,如下所示:

    - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {     
        UIDevice* thisDevice = [UIDevice currentDevice];
        if (thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
        {
            return true;
        }
        else
        {
            return interfaceOrientation == UIDeviceOrientationPortrait;
        }
    }
    

    【讨论】:

      【解决方案2】:

      运行 iOS 6+ 的应用也需要实现 ViewController:

      - (NSInteger)supportedInterfaceOrientations
      

      和/或 AppDelegate 的:

      - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
      

      例如,

      - (NSInteger)supportedInterfaceOrientations
      {
          if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
              return UIInterfaceOrientationMaskAll;
          }
          return UIInterfaceOrientationMaskPortrait;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-24
        • 1970-01-01
        • 2011-05-06
        • 1970-01-01
        • 2010-10-31
        • 1970-01-01
        相关资源
        最近更新 更多