【问题标题】:iPad 2 UIImagePickerController camera auto-rotation driving me mad!iPad 2 UIImagePickerController 相机自动旋转让我发疯!
【发布时间】:2011-05-15 09:03:18
【问题描述】:

我一直在尝试解决这个问题,但无济于事。

我在 iPad 2 上使用相机 - 我的应用程序是横向的,但我想在纵向模式下使用相机。我似乎无法强制 ImagePicker a 进入纵向模式,并强制 b 停止自动旋转。

有什么方法可以强制 ImagePicker 变成纵向(或横向),和/或阻止它自动旋转?

即使应用程序处于横向状态并且设置为仅在横向方向返回 YES,ImagePicker 也会忽略这一点并在您旋转 iPad 2 时旋转为纵向。

如果我可以强制它停留在横向,那么(虽然不理想)我可以重新设计应用程序以在横向中使用相机,但我似乎无法做到这一点!

非常感谢任何帮助!

【问题讨论】:

    标签: ipad camera rotation uiimagepickercontroller


    【解决方案1】:

    你需要重写的方法被调用:

    _isSupportedInterfaceOrientation:

    所以它应该看起来像这样:

    @interface PortraitImagePickerController : UIImagePickerController {
    
    }
    
    @end
    
    
    
    
    
    @implementation PortraitImagePickerController
    - (BOOL)_isSupportedInterfaceOrientation:(UIDeviceOrientation)orientation{
        return UIDeviceOrientationIsPortrait(orientation);
    }
    @end
    

    但这绝对是私有方法,因此 Apple 可能会拒绝您的应用

    【讨论】:

    • 谢谢你——我最后做的只是一个软糖——当设备从纵向旋转时,我关闭了 ImagePicker 并显示了一张建议将设备旋转回纵向的图像 -苹果通过了,但我不太喜欢这个解决方案。
    • 这正是我所需要的。有人知道这是否会让我的应用被拒绝?
    • 我们的应用程序已被接受。虽然 - 无论如何使用它是有风险的
    【解决方案2】:

    好吧,我找到了一种更方便的方法,并且没有使用私有代码的风险。

    子类 a UIImagePickerController 并在其 .m 文件中添加以下方法。

    - (NSUInteger)supportedInterfaceOrientations{
    
        return UIInterfaceOrientationMaskPortrait;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-30
      • 1970-01-01
      • 1970-01-01
      • 2011-09-27
      • 2011-05-30
      相关资源
      最近更新 更多