当我尝试将cameraOverlayView应用到UIImagePickerController时,它不会出现。我已经阅读了一些关于如何应用这一点的文档,我的代码看起来都是正确的。如果有人能解释为什么我的覆盖还没有开始的话,我真的会理解的。
//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];解决办法:
我找到了解决方案:它既合并了Visput的建议,又合并了fguchelaar的,然后我删除了btnView.alpha = 0.3,用btnView.opaque = NO;替换了它,这就成功了。混乱的颜色,现在我的覆盖是完美的工作。
发布于 2014-04-30 22:02:26
覆盖视图的框架大小为零:
UIView *btnView = [[UIView alloc] initWithFrame:CGRectZero];像这样改变它,你就会看到它:
UIView *btnView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 1024];更新:
还启用clipsToBounds标志:btnView.clipsToBounds = YES;
https://stackoverflow.com/questions/23398654
复制相似问题