简体   繁体   English

iPhone / iPad相机覆盖视图自动旋转问题UIImagePickerController

[英]iPhone/iPad Camera Overlay View AutoRotation Issue UIImagePickerController

According to Apple, we must not subclass the UIImagePickerController class. 根据苹果公司的说法,我们不能将UIImagePickerController类作为子类。 From the docs: 从文档:

Important: The UIImagePickerController class supports portrait mode only. 重要:UIImagePickerController类仅支持纵向模式。 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. 您可以将自定义视图分配给cameraOverlayView属性,并使用该视图显示其他信息或管理摄像头界面与您的代码之间的交互。

But If we want to overlay a view on the camera, we can do so as follows: 但是,如果要在相机上叠加视图,可以按以下步骤进行:

imagePickerController.cameraOverlayView = overlayView

After implementing the camera overlay view, The view adjusts itself automatically in iPads. 实施相机叠加视图后,该视图会在iPad中自动调整。 However, this is not the case with the iPhones. 但是,iPhone并非如此。

Query: Can we set the autorotation of the cameraOverlayView in iPhone as in iPad? 查询:我们可以像在iPad中那样在iPhone中设置cameraOverlayView的自动旋转吗?

If not, what is the optimum way of rotating the cameraOverlayView with UIDeviceOrientationDidChangeNotification 如果不是,使用UIDeviceOrientationDidChangeNotification旋转cameraOverlayView的最佳方法是什么

You can subclass UIImagePickerController and can instantiate it. 您可以UIImagePickerController并将其实例化。 Apple saying that you should not subsclass it is for other reason. 苹果公司说,您不应因为其他原因而取代它。 You can not change default controls of UIImagePickerController like swap camera, flash turn on off, take photo or video etc. For that you have to create overlay view and should set as cameraOverlayView of UIImagePickerController . 您不能更改UIImagePickerController默认控件,例如交换相机,关闭闪光灯,拍摄照片或视频等。为此,您必须创建overlay view并应将其设置为UIImagePickerController cameraOverlayView That's it, otherwise you can subclass UIImagePickerController . 就是这样,否则您可以子类化UIImagePickerController

So, now solution for your issue : 因此,现在解决您的问题:

Subclass UIImagePickerController and in that class implement below two methods like, 子类UIImagePickerController并在该类中实现以下两个方法,例如,

 -(BOOL)shouldAutorotate{

    return NO;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskPortrait;
}

and then instantiate that class instead of UIImagePickerController . 然后实例化该类而不是UIImagePickerController

and your orientation issue for your overlayview will be solved. 并且您的overlayview方向问题将得到解决。 It will always remain in portrait mode. 它将始终保持纵向模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM