我正在尝试使用自定义叠加层。我的项目中有一个PNG图像。边缘有边框,而中心是透明的。在我的代码中,我有:
self.imagePickerController = [[UIImagePickerController alloc] init];
[self.imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
[self.imagePickerController setDelegate:self];
[self.imagePickerController setCameraDevice:UIImagePickerControllerCameraDeviceRear];
[self.imagePickerController setShowsCameraControls:NO];
UIView *myOverlay = [[UIView alloc] initWithFrame:self.view.bounds];
UIImage *overlayImg = [UIImage imageNamed:@"overlay.png"];
UIImageView *overlayBg = [[UIImageView alloc] initWithImage:overlayImg];
[myOverlay addSubview:overlayBg];
[self.navigationController presentViewController:self.imagePickerController animated:YES completion:nil];
当我按下按钮呈现控制器时,我明白了:
我做错了什么是让相机不占用整个屏幕,还没有添加overlay.png图像?这就是叠加层的样子,只记得白色部分实际上是透明的:
更新
我已更新代码:
self.imagePickerController = [[UIImagePickerController alloc] init];
[self.imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
[self.imagePickerController setDelegate:self];
[self.imagePickerController setCameraDevice:UIImagePickerControllerCameraDeviceRear];
[self.imagePickerController setShowsCameraControls:NO];
UIView *myOverlay = [[UIView alloc] initWithFrame:self.view.bounds];
UIImage *overlayImg = [UIImage imageNamed:@"overlay.png"];
UIImageView *overlayBg = [[UIImageView alloc] initWithImage:overlayImg];
[myOverlay addSubview:overlayBg];
[self.imagePickerController.view addSubview:myOverlay];
[self.navigationController presentViewController:self.imagePickerController animated:YES completion:nil];
它现在看起来像这样,变得更好,但相机仍占据屏幕的一小部分,并且框架的尺寸不是很合适。
答案 0 :(得分:0)
您需要在myOverlay
和imagePickerController
之间建立联系,因此请尝试将myOverlay
添加为imagePickerController.view
的子视图。