ios - iPhone/iPad 相机叠加 View 自动旋转问题 UIImagePickerController

标签 ios objective-c iphone xcode uiimagepickercontroller

根据 Apple 的规定,我们不能子类化 UIImagePickerController 类。来自文档:

Important: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.

但是如果我们想在相机上叠加 View ,我们可以这样做:

imagePickerController.cameraOverlayView = overlayView

实现相机覆盖 View 后,该 View 会在 iPad 中自动调整。然而,iPhone 的情况并非如此。

查询: 我们可以像iPad一样在iPhone中设置cameraOverlayView的自动旋转吗?

如果没有,使用UIDeviceOrientationDidChangeNotification旋转cameraOverlayView的最佳方式是什么

最佳答案

您可以子类化 UIImagePickerController并可以实例化它。苹果说你不应该继承它是有其他原因的。您无法更改 UIImagePickerController 的默认控件例如交换相机、打开闪光灯、拍照或录像等。为此,您必须创建 overlay view并应设置为 cameraOverlayViewUIImagePickerController 。就是这样,否则你可以子类 UIImagePickerController .

那么,现在解决您的问题:

子类UIImagePickerController并在该类中实现以下两个方法,例如,

 -(BOOL)shouldAutorotate{

    return NO;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskPortrait;
}

然后实例化该类而不是 UIImagePickerController .

您的叠加 View 的方向问题将得到解决。它将始终保持纵向模式。

关于ios - iPhone/iPad 相机叠加 View 自动旋转问题 UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30890750/

相关文章:

iphone - 从未调用过 alertView didDismissWithButtonIndex

iOS:当应用程序因任何崩溃而退出时是否有任何委托(delegate)方法

objective-c - DynamoDB 上的条件更新项

objective-c - 从 CVImageBufferRef 获取内存所有权

ios - 每次打开应用程序时刷新 View 和数据

ios - 在具有特定事件 ID 的日历应用程序中打开 "Event Details"

iphone - 使用 REST api 后端开发 iOS 应用程序(基于数据库)

ios - 使用帐户框架访问 Facebook 时限制权限

iphone - 如何找出用于构建 *.ipa 文件的配置文件?

iphone - 如何在iPhone中使用下拉菜单?