根据 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
并应设置为 cameraOverlayView
的UIImagePickerController
。就是这样,否则你可以子类 UIImagePickerController
.
那么,现在解决您的问题:
子类UIImagePickerController
并在该类中实现以下两个方法,例如,
-(BOOL)shouldAutorotate{
return NO;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
然后实例化该类而不是 UIImagePickerController
.
您的叠加 View 的方向问题将得到解决。它将始终保持纵向模式。
关于ios - iPhone/iPad 相机叠加 View 自动旋转问题 UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30890750/