【问题标题】:IOS7 Xcode 5 universal app won't rotate on iphone, but will on ipadIOS7 Xcode 5 通用应用程序不会在 iphone 上旋转,但会在 ipad 上旋转
【发布时间】:2014-03-11 10:05:14
【问题描述】:

我有一个最初是为 ipad 构建的应用程序,并且我正在将其变成一个通用应用程序。我已经让整个应用程序正常工作,普遍来说,所有功能都正常工作并且大小正确。除了在 iphone 上应用程序不会向任何方向旋转,它保持在纵向模式。

这是我得到的:

  • 从 Targets/General 部分检查 iPhone 设备方向:(纵向、横向左侧和横向右侧)均已选中
  • 在我的 Main_iPhone.storyboard 中,我有一个根视图控制器连接到一个 uinavigation 控制器,该控制器在第一次加载应用程序时会弹出一个设置 (uitableview)。 (与 ipad 故事板相同,但大小适用于 iphone)
  • 视图控制器以编程方式将 xib:TakePhotoView.xib 加载到 cameraOverlayView 上,它上面有一个标签,告诉用户触摸屏幕来拍照。

再次,这在 ipad 上完美运行,我对 ios 开发非常陌生。我实际上有一个朋友开发了 ipad 应用程序,我将它作为我深入研究 ios 的起点,因此我正试图将它变成一个通用应用程序来让我的脚湿透。

任何指针将不胜感激。我用这个把头发拉出来。

【问题讨论】:

    标签: iphone ios7 xcode5


    【解决方案1】:
     (BOOL) shouldAutorotate{
        return YES;
    }
    - (NSUInteger) supportedInterfaceOrientations{
        return UIInterfaceOrientationMaskLandscape;
    }
    - (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
        return UIInterfaceOrientationLandscapeRight; //you can choose either landscape orientation here
    }
    

    【讨论】:

    • 我已经在我的 viewController 中尝试过了,但它不起作用。使用 NSLog 我可以看到 shouldAutorotate 被触发但 iphone 上没有任何实际旋转。
    【解决方案2】:

    终于弄明白了。它是 UIImagePickerController。出于某种原因,它非常适合 ipad,但我需要为 iphone 覆盖它。

    #import "UIImagePickerController+rotation.h"
    
    @interface UIImagePickerController (private)
    
    - (BOOL)shouldAutorotate;
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
    - (NSUInteger)supportedInterfaceOrientations;
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
    
    @end
    
    
    @implementation UIImagePickerController (Private)
    
    - (NSUInteger)supportedInterfaceOrientations {
    
        return UIInterfaceOrientationMaskAll;
    }
    
    - (BOOL)shouldAutorotate {
    
        return UIInterfaceOrientationMaskAll;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        {
            return UIInterfaceOrientationPortrait;
        }
        else
        {
            return UIInterfaceOrientationLandscapeRight;
        }
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return YES;
    }
    @end
    

    【讨论】:

      猜你喜欢
      • 2012-12-27
      • 1970-01-01
      • 2012-09-24
      • 1970-01-01
      • 2013-10-06
      • 1970-01-01
      • 2012-06-05
      • 2011-09-21
      • 2011-06-22
      相关资源
      最近更新 更多