gpt4 book ai didi

iphone - UIImagePickerController 覆盖 View 和显示相机控件问题

转载 作者:行者123 更新时间:2023-12-03 19:24:38 25 4
gpt4 key购买 nike

我尝试在 UIImagePickerController 上使用自定义叠加层,并且还能够移动和缩放生成的图像。问题是当我设置 showsCameraControls=YES 时,叠加层不会显示,但我可以使用移动和缩放功能。但是,当 showsCameraControls=NO 时,会出现叠加层,但当我拍照时,我什至没有选择裁剪图像。从 xib 加载的实际 View 只是一个带有两个按钮的 UIToolbar,其中一个按钮拍摄照片

我有一个 Controller (OverlayViewController),它在 View 时从 xib 文件加载叠加层。该 Controller 还有一个 UIImagePickerController,因此它将 UIImagePickerController 的覆盖层设置为 OverlayController 的 View 。在不同的 Controller 中调用第一个方法来设置并显示它。总之,我需要能够看到 overlayView 并使用它的按钮拍摄照片,然后可以移动和缩放

-(void) openCameraForImage
{

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
self.overlayViewController =
[[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];

// as a delegate we will be notified when pictures are taken and when to dismiss the image picker
self.overlayViewController.delegate = self;

[self.overlayViewController setupImagePicker:UIImagePickerControllerSourceTypeCamera];
[self presentModalViewController:self.overlayViewController.imagePickerController animated:YES];
}
else {
[Common ShowAlert:@"Alert" andMessage:@"There is no camera on this device"];
}

}

此方法位于 OverlayViewController 中,负责设置 Overlay。

- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType
{
self.imagePickerController.sourceType = sourceType;
[self.imagePickerController setAllowsEditing:YES];

if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
// user wants to use the camera interface
//
self.imagePickerController.showsCameraControls = NO; //This line allows overlay to show but move and scale doesn't work
self.imagePickerController.allowsEditing = YES;
//[self.view setUserInteractionEnabled:NO];

if ([[self.imagePickerController.cameraOverlayView subviews] count] == 0)
{
// setup our custom overlay view for the camera
//
// ensure that our custom view's frame fits within the parent frame
CGRect overlayViewFrame = self.imagePickerController.cameraOverlayView.frame;
CGRect newFrame = CGRectMake(0.0,
CGRectGetHeight(overlayViewFrame) -
self.view.frame.size.height - 10.0,
CGRectGetWidth(overlayViewFrame),
self.view.frame.size.height + 10.0);
self.view.frame = newFrame;
self.imagePickerController.cameraOverlayView = self.view;
}
}
}

OverlayViewConroller 中的此方法拍摄图片

- (IBAction)takePhoto:(id)sender
{
[self.imagePickerController takePicture];
}

最佳答案

我认为你可以将图像选择器代码放入 openCameraForImage

在您的 OverlayViewController 中,只需使用它来纯粹显示相机的叠加层。

@implementation RiskCameraOverlayViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

[self.view setBackgroundColor:[UIColor blackColor]];

opUpImage = [UIImage imageNamed:@"camera_overlay_op_up"];
opDownImage = [UIImage imageNamed:@"camera_overlay_op_down"];

opUpFrameBegin = CGRectMake(0, -50, 320, 358);
opUpImageView = [[UIImageView alloc] initWithFrame:opUpFrameBegin];
[opUpImageView setImage:opUpImage];

opDownFrameBegin = CGRectMake(0, 265, 320, 314);
opDownImageView = [[UIImageView alloc] initWithFrame:opDownFrameBegin];
[opDownImageView setImage:opDownImage];

[self.view addSubview:opUpImageView];
[self.view addSubview:opDownImageView];

}

您可能会遇到“使用照片”或“重拍”不起作用的问题,请执行以下操作

[self.view removeFromSuperview];

关于iphone - UIImagePickerController 覆盖 View 和显示相机控件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11385757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com