UIImagePickerController cameraViewTransform 在 iOS 10 中不起作用
Posted
技术标签:
【中文标题】UIImagePickerController cameraViewTransform 在 iOS 10 中不起作用【英文标题】:UIImagePickerController cameraViewTransform is not working in iOS 10 【发布时间】:2016-11-02 07:36:57 【问题描述】:我已经在我的应用程序中实现了相机覆盖视图。相机覆盖视图在 ios 9 中运行良好。但 iOS 10 cameraViewTransform 无法正常工作如何解决此问题。请指导我。谢谢
我的工作代码
CGSize screenBounds = [UIScreen mainScreen].bounds.size;
CGFloat cameraAspectRatio = 4.0f/3.0f;
CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
CGFloat scale = screenBounds.height / camViewHeight;
picker.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, scale, scale);
更新
OverlayView *overlay = [[OverlayView alloc]
initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
picker =
[[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.navigationBarHidden = NO;
picker.toolbarHidden = YES;
// Device's screen size (ignoring rotation intentionally):
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
float cameraAspectRatio = 4.0 / 3.0;
float imageWidth = floorf(screenSize.width * cameraAspectRatio);
float scale = ceilf((screenSize.height / imageWidth) * 10.0) / 10.0;
picker.cameraViewTransform = CGAffineTransformScale(CGAffineTransformIdentity, 2, 2);
picker.cameraOverlayView = overlay;
picker.allowsEditing = NO;
UIPinchGestureRecognizer *pinchRec = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(zoom:)];
[overlay addGestureRecognizer:pinchRec];
overlay.image =image;
[self.navigationController presentViewController:picker animated:NO completion:nil];
【问题讨论】:
【参考方案1】:iOS 10.2 修复了这个问题!您现在可以在再次展示相机之前使用cameraViewTransform
属性。
【讨论】:
【参考方案2】:试试这个:
我之前在 IOS 9.3 中也遇到过同样的问题。这是我使用的代码
//transform values for full screen support
#define CAMERA_TRANSFORM_X 1
#define CAMERA_TRANSFORM_Y 1.12412
if (IS_IPAD)
CGAffineTransformScale(objImagePickerController.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
else if (IS_IPHONE_5_Land||IS_IPHONE_4_Land||IS_IPHONE_6_Land||IS_IPHONE_6_PLUS_Land)
objImagePickerController.cameraViewTransform = CGAffineTransformScale(CGAffineTransformIdentity, 2, 2);
希望这会有所帮助。如需更多帮助:UIImagePickerController's cameraViewTransform is ignoring 'scaling' and 'translation' on iOS 10 beta
【讨论】:
我已经使用了您的代码,但仍然无法正常工作 @Jamshed Alam 您在初始化相机时是否使用了 picker.allowsEditing = NO ?以上是关于UIImagePickerController cameraViewTransform 在 iOS 10 中不起作用的主要内容,如果未能解决你的问题,请参考以下文章
UIImagePickerController cameraViewTransform 在 iOS 10 中不起作用
SVG 覆盖在 UIImagePickerController 之上,UIImagePickerController 响应手势(iPhone/iOS)