簡體   English   中英

cameraOverlayView不適用

[英]cameraOverlayView not applying

當我嘗試將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; 然后就成功了。 亂七八糟的顏色,現在我的覆蓋層可以正常工作了。

疊加視圖的框架大小為零:

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

像這樣更改它,您將看到:

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

更新:
還啟用clipsToBounds標志: btnView.clipsToBounds = YES;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM