Imagepicker覆盖仅在ios 10中不全屏显示

Posted

技术标签:

【中文标题】Imagepicker覆盖仅在ios 10中不全屏显示【英文标题】:Imagepicker overlay not display in fullscreen only in ios 10 【发布时间】:2016-10-03 06:51:16 【问题描述】:

我正在使用 Imagepicker 覆盖来捕捉照片。在 ios 9 中,我的代码运行良好,但是当我在 iOS 10 上运行我的代码时,它会在底部显示一个空格,这在 iOS 9 上没有显示。我试图解决它,但我无法做到。

这是我产生问题的代码:

- (void)openCamerawithOption :(UIImagePickerControllerCameraCaptureMode)camType

    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    

        [[NSOperationQueue mainQueue] addOperation:[NSBlockOperation blockOperationWithBlock:^
            [self createImagePicker:camType];
        ]];
    


-(void)createImagePicker :(UIImagePickerControllerCameraCaptureMode)camType

    if (!imagePickerController) 
        imagePickerController = [[NonRotatableImagePickerController alloc] init];
    
    //[imagePickerController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height+(iOS7?0:20.0))];
    [APPSINGLETON setBorder:imagePickerController.view color:[UIColor redColor]];

    imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePickerController.allowsEditing = YES;
    imagePickerController.videoMaximumDuration = 60.0;

    if (iOS7) 
        CGSize screenBounds = APPDELEGATE.screenSize;
        CGFloat cameraAspectRatio = 4.0f/3.0f;
        CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
        CGFloat scale = screenBounds.height / camViewHeight;
        imagePickerController.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
        imagePickerController.cameraViewTransform = CGAffineTransformScale(imagePickerController.cameraViewTransform, scale, scale);
     else 
        float cameraAspectRatio = 4.0 / 3.0;
        float imageWidth = floorf(APPDELEGATE.screenSize.width * cameraAspectRatio);
        float scale = ceilf(((APPDELEGATE.screenSize.height+20.0) / imageWidth) * 10.0) / 10.0;
        imagePickerController.cameraViewTransform = CGAffineTransformMakeScale(scale, scale);
    

    imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString )kUTTypeMovie, (NSString )kUTTypeImage, nil];
    imagePickerController.cameraCaptureMode = camType;
    imagePickerController.showsCameraControls = NO;
    imagePickerController.toolbar.hidden=YES;
    imagePickerController.wantsFullScreenLayout = YES;

    // not all devices have two cameras or a flash so just check here
    if ([UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceRear])
    
        imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    
    else
    
        imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    

    if ([UIImagePickerController isFlashAvailableForCameraDevice:imagePickerController.cameraDevice])
    
        imagePickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
    

    [self performSelectorOnMainThread:@selector(presentPicker) withObject:nil waitUntilDone:YES];


-(void)presentPicker

    [self presentViewController:imagePickerController animated:YES completion:nil];
    imagePickerController.cameraOverlayView = transparentView;
 

这是截图

更新

self.presentViewController(
        self.imagePicker,
        animated: true,
        completion: 
            let screenSize = UIScreen.mainScreen().bounds.size
            let ratio: CGFloat = 4.0 / 3.0
            let cameraHeight: CGFloat = screenSize.width * ratio
            let scale: CGFloat = screenSize.height / cameraHeight

            self.imagePicker.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenSize.height - cameraHeight) / 2.0)
            self.imagePicker.cameraViewTransform = CGAffineTransformScale(self.imagePicker.cameraViewTransform, scale, scale)
        
    )

This solution from below is working for me except when I rotate the device the same issue returns.

UIImagePickerController's cameraViewTransform is ignoring 'scaling' and 'translation' on iOS 10 beta

【问题讨论】:

好像是ios10的bug。检查此板 ***.com/questions/39124794/…> @AndrewVeresov 您的解决方案适用于首次加载,但是当我旋转屏幕时,同样的问题再次出现,您能指导我吗? 【参考方案1】:

@chirag shah 我没有在 ios10 中找到很好的 imagePicker 转换解决方案。我只是从我的 ios 10 项目中省略了 imagepicker,并将 AVCaptureSession 与视频重力 AVLayerVideoGravityResizeAspectFill 一起用于 AVCaptureVideoPreviewLayer 对象。效果很好。

【讨论】:

我需要更改很多东西,所以我无法将 ImagePickerOverlay 更改为 AVLayerVideoGravityResizeAspectFill 你的评论对我有用,为什么我接受你的回答【参考方案2】:

presentPicker 方法中的 transparentView 是什么?尝试像这样设置它的框架:

transparentView.frame = imagePickerController.view.bounds;
imagePickerController.cameraOverlayView = transparentView;
[self presentViewController:imagePickerController animated:YES completion:nil];

【讨论】:

【参考方案3】:

实际上我遇到了同样的问题。由于找不到合适的解决方案,我只是将视图的 ty 转换为类似

CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, sizeMissingAtBottom);
imagePickerController.cameraViewTransform = translate;

然后,如果需要,您可以CGAffineTransformScale 进行翻译。

【讨论】:

我检查了你的答案

以上是关于Imagepicker覆盖仅在ios 10中不全屏显示的主要内容,如果未能解决你的问题,请参考以下文章

微信公众号开发--视频不全屏展示

故事板:如何弹出不全屏

应用程序仅在 iOS 6 中旋转,在 iOS 5 中不旋转

UISplitViewController 的详细视图仅在 iOS8 上采用全屏

iPhone 5 iOS 6 模拟器 imagePicker DidFinish 不工作

html5开发,android中的微信内置浏览器如何让video标签的视频不全屏播放