自定义相机叠加层不适用于 iPad

Custom Camera Overlay Not Working on iPad

我正在尝试让自定义叠加层正常工作。我的项目中有一个 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];

现在看起来是这样,越来越好,但相机仍然只占屏幕的一小部分,而且边框尺寸不太合适。

您需要在 myOverlayimagePickerController 之间建立联系,因此尝试将 myOverlay 添加为 imagePickerController.view 的子视图。