ios - UIImagePickerController 不是全屏

标签 ios objective-c cocoa-touch ios7

自从 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,具有透明背景,可在屏幕上绘制一些自定义控件。

enter image description here

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

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

最佳答案

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

wantsFullScreenLayout

已弃用并被忽略。在某些情况下,此修复有效(在 View Controller 类中):

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

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

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

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

无论如何,让我知道你的进展情况。

关于ios - UIImagePickerController 不是全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19006272/

相关文章:

iphone - 你能用 Ruby 开发原生 iPhone 应用程序吗?

cocoa - 仪器中的内存泄漏

objective-c - UITextField 清除按钮不显示

objective-c - 有一半的 UILabel 文本加粗,一半没有?

ios - SwiftyJSON 未正确从文件初始化

ios - UIImage 缩放比例

ios - 翻转 UILabel

ios - 如何在 iOS 应用程序中通知用户调用请求?

ios - SpriteKit - 如何添加具有特定距离的对象

ios - WatchKit 数据不显示