繁体   English   中英

UIImagePickerController不是全屏

[英]UIImagePickerController not full screen

自iOS7升级以来,我有一个奇怪的UIImagePickerController行为。 在这个应用程序中,我使用带有cameraOverlayViewUIImagePickerController

在iOS6中,我使用以下代码调用了UIImagePickerController

_picker = [[UIImagePickerController alloc] init];

if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
    _picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    _picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
    _picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    _picker.showsCameraControls = NO;
    _picker.navigationBarHidden = NO;
    _picker.toolbarHidden = YES;
    _picker.wantsFullScreenLayout = YES;

    _overlayViewController = [[OverlayViewController alloc] init];
    _overlayViewController.picker = _picker;
    _overlayViewController.frameSize = self.frameSize;
    _overlayViewController.delegate = self;
    _picker.cameraOverlayView = _overlayViewController.view;
}
else {
    _picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

}
_picker.delegate = self;

OverlayViewController是一个UIViewController ,其透明背景在屏幕上绘制一些自定义控件。

在此输入图像描述

但是现在在iOS 7中,相机通过状态栏绘制,并且在实时摄像机视图下方会出现一个黑条。

我可以通过将CGAffineTransformMakeTranslation应用于UIImagePickerControllercameraViewTransform属性来解决这个问题,但为什么会这样呢?

在iOS 7中,默认情况下UIViewController视图占用整个屏幕区域,包括状态栏。

wantsFullScreenLayout

已弃用并被忽略。 在某些情况下,此修复工作(在视图控制器类中):

if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
    [self setEdgesForExtendedLayout:UIRectEdgeNone];
}

在其他情况下,它有点复杂。 现在已经很晚了,所以看看你如何使用它。 值得注意的事项 - 在UIViewController中,以下代码将在iOS 6和iOS 7上提供正确的状态栏高度,如果必须使用CGRect数学对齐事物:

if (UIDeviceOrientationIsLandscape(self.interfaceOrientation)) {
            statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.width;
        } else {
            statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
        }

然后不要忘记在Interface Builder中,有新的“iOS 6 delta”调整,允许您设计iOS 7,然后使用偏移来校正iOS 6。

无论如何,让我知道你怎么走。

基于其他一些SO线程等我对该问题的理解是,UIImagePickerController不能通过[UIViewController -prefersStatusBarHidden]来管理状态栏。

这意味着您必须完全禁用视图控制器状态栏管理,通过plist,或找出一种方法让UIImagePickerController执行我们想要的操作。 假设你不是在寻找前者,我可以说我已经在后者中取得了成功,将选择器放在一个包装控制器中,可以完成我想要的操作(但是如果你仍然需要,请回到之前的代码中)检测/支持iOS6):

@interface PickerContainer : UIViewController

@property ( nonatomic, weak ) UIImagePickerController* picker;

@end

@implementation PickerContainer

- (void) setPicker: (UIImagePickerController*) picker
{
    [self addChildViewController: picker];
    [picker didMoveToParentViewController: self];

    self->_picker = picker;
}

- (void) viewDidLoad
{
    [super viewDidLoad];

    self.picker.view.frame = self.view.bounds;
    [self.view addSubview: self.picker.view];
}

// Will have no effect in ios6 -- see [-init] for that option
- (BOOL) prefersStatusBarHidden { return YES; }

- (id) init
{
    if ( ! ( self = [super init] ) ) return nil;

    if ( detectThatThisIsIos6() ) self.wantsFullScreenLayout = YES;

    return self;
}

@end

这将适合你,缩放相机,你将在底部有一个黑色条,但它将被工具栏覆盖https://stackoverflow.com/a/15803947

暂无
暂无

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

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