使用自定义UIImagePicker叠加导致白色空白屏幕相机预览

时间:2014-01-06 05:37:26

标签: ios iphone ios7 uiimagepickercontroller

我目前正在为我的相机控件和UIImagePickerController使用自定义叠加层,并进行以下设置:

self.imagePickerController = [[UIImagePickerController alloc] init];
    self.imagePickerController.delegate = self;
    //... Additional set up code omitted
    self.imagePickerController.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
    //!---- If below code deleted and use default ImagePickerController, all works fine
    if (self.imagePickerController.sourceType == UIImagePickerControllerSourceTypeCamera)
    {
        self.imagePickerController.showsCameraControls = NO;

        [[NSBundle mainBundle] loadNibNamed:@"overlayView2" owner:self options:nil];
        self.overlayView.frame = self.imagePickerController.cameraOverlayView.frame;
        self.imagePickerController.cameraOverlayView = self.overlayView;
        self.overlayView = nil;

        CGSize screenSize = [[UIScreen mainScreen] bounds].size;

        float cameraAspectRatio = 4.0 / 4.0;
        float imageWidth = floorf(screenSize.width * cameraAspectRatio);
        float scale = ceilf((screenSize.height / imageWidth) * 10.0) / 10.0;

        self.imagePickerController.cameraViewTransform = CGAffineTransformMakeScale(scale, scale);

    }

使用上面的代码,我得到以下白色相机预览屏幕:

enter image description here

但是,根据上述评论,如果我使用默认的UIImagePickerController,那么预览将启动并正常工作:

enter image description here

我不确定设置的哪些方面导致白色空白屏幕。一个关于类似问题的question提到录音,但由于我只专注于图片,我不确定它是如何相关的。

感谢您的帮助!

0 个答案:

没有答案