简体   繁体   English

cameraOverlayView不适用

[英]cameraOverlayView not applying

When I try and apply a cameraOverlayView to UIImagePickerController, it doesn't show up. 当我尝试将cameraOverlayView应用于UIImagePickerController时,它没有显示。 I have read through some documentation on how to apply this, and my code all looks correct. 我已经阅读了一些有关如何应用此方法的文档,并且我的代码看起来都正确。 If someone could explain why my overlay isn't starting, I would really appriciate it. 如果有人可以解释为什么我的覆盖图没有开始,我会很高兴。

//Start the camera up

UIImagePickerController *imageViewPickerController = [[UIImagePickerController alloc] init];

//Hide default UI elements

imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imageViewPickerController.showsCameraControls = NO;
imageViewPickerController.navigationBarHidden = YES;
imageViewPickerController.toolbarHidden = YES;

//Start the button overlay

UIView *btnView = [[UIView alloc] initWithFrame:imageViewPickerController.view.bounds];
btnView.backgroundColor = [UIColor whiteColor];
btnView.alpha = 0.3;
btnView.clipsToBounds = YES;

//Add a button to the overlay

UIButton *snapButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 1024, 1024)];
snapButton.backgroundColor = [UIColor blackColor];
[btnView addSubview:snapButton];

//Overlay button view

imageViewPickerController.cameraOverlayView = btnView;

//Fix for iPhone 5 and make fullscreen

CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -55.0);
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333);
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));
CGAffineTransform transform = CGAffineTransformConcat(translate, scale);
transform = CGAffineTransformConcat(transform, rotate);
imageViewPickerController.cameraViewTransform = transform;

//Let's present it all

[self presentViewController:imageViewPickerController
                   animated:NO
                 completion:NULL];

SOLUTION: 解:

I found the solution: it was both merging in Visput's suggestion, and fguchelaar's. 我找到了解决方案:这既是Visput的建议,也是fguchelaar的建议。 I then removed the btnView.alpha = 0.3 and replaced it with btnView.opaque = NO; 然后,我删除了btnView.alpha = 0.3并替换为btnView.opaque = NO; and that did the trick. 然后就成功了。 Messed around with colors and now my overlay is working perfectly. 乱七八糟的颜色,现在我的覆盖层可以正常工作了。

Frame of your overlay view has zero size: 叠加视图的框架大小为零:

UIView *btnView = [[UIView alloc] initWithFrame:CGRectZero];

Change it like this and you will see it: 像这样更改它,您将看到:

UIView *btnView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 1024];

Update: 更新:
Also enable clipsToBounds flag: btnView.clipsToBounds = YES; 还启用clipsToBounds标志: btnView.clipsToBounds = YES;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM