UIImagePickerController的cameraViewTransform忽略了iOS 10 beta上的“缩放”和“翻译” [英] UIImagePickerController's cameraViewTransform is ignoring 'scaling' and 'translation' on iOS 10 beta

查看:194
本文介绍了UIImagePickerController的cameraViewTransform忽略了iOS 10 beta上的“缩放”和“翻译”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用下面的代码来扩展我的UIImagePickerController的实时预览以填充整个屏幕。到目前为止,这完美地运作在几天之前,我在iPhone 5上安装了iOS 10 beta 7,它不再扩展。我可以在UIImagePickerController的视图底部看到黑色补丁。似乎 cameraViewTransform 忽略 CGAffineTransformMakeScale CGAffineTransformMakeTranslation 调用。

I have been using below code to scale my UIImagePickerController's live preview to fill the entire screen. This worked perfectly till now. Before few days, I installed iOS 10 beta 7 on an iPhone 5 and it doesn't scale anymore. I can see black patch at the bottom of UIImagePickerController's view. Seems like cameraViewTransform is ignoring the CGAffineTransformMakeScale and CGAffineTransformMakeTranslation calls.

这就是我启动相机控制器的方法。我已将allowsEditing和showsCameraControls设置为否,以便提供我自己的自定义叠加视图。

objImagePickerController =[[UIImagePickerController alloc] init];

objImagePickerController.delegate = self;
objImagePickerController.sourceType =UIImagePickerControllerSourceTypeCamera;
objImagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
objImagePickerController.allowsEditing = NO;
objImagePickerController.showsCameraControls= NO;

这是我用来缩放相机实时预览的内容。

CGSize screenSize = [[UIScreen mainScreen] bounds].size;
float screenHeight= MAX(screenSize.height, screenSize.width);
float screenWidth= MIN(screenSize.height, screenSize.width);

float cameraAspectRatio = 4.0 / 3.0;
float imageWidth = floorf(screenWidth * cameraAspectRatio);
float scale = ceilf((screenHeight / imageWidth) * 10.0) / 10.0;

objImagePickerController.cameraViewTransform= CGAffineTransformMakeScale(scale, scale);

这是我将相机视图添加为子视图而不是传统的模态显示方法的方法,符合我自己的要求。

 [[[UIApplication sharedApplication] keyWindow]addSubview:objImagePickerController.view];

在iOS 10 beta 8上运行的iPhone 5s截图

在iOS 8.2上运行的iPhone 5s的屏幕截图

从上面的截图中可以看出, cameraViewTransform 不尊重iOS 10测试版中的 CGAffineTransformMakeScale

As noticeable from the above screenshots, the cameraViewTransform doesn't respect the CGAffineTransformMakeScale in iOS 10 beta.

其他人是否面临这个问题?这是iOS 10 beta OS中出现的一种非常奇怪的行为。我无法找到解决方法。请指教。

Did anybody else face this issue? This is a really weird behavior appearing in iOS 10 beta OS. I am unable to find a workaround for this. Please advise.

注意:: objImagePickerController是UIImagePickerController的一个实例。

NOTE:: objImagePickerController is an instance of UIImagePickerController.

推荐答案

奇怪的是,它只允许我们在演示文稿完成后转换它。

Strangely it only allows us to transform it after the presentation was completed.

示例:

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 code will transform the camera view to match the screen size.

请注意,这是一种解决方法。它有效,但用户会看到它在演示时调整大小。

Note that this is a workaround. It works, but the user will see it resizing upon presentation.

这篇关于UIImagePickerController的cameraViewTransform忽略了iOS 10 beta上的“缩放”和“翻译”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆