iOS-在UIImagePickerController CustomOverlayView中点击按钮后拍照

iOS-在UIImagePickerController CustomOverlayView中点击按钮后拍照,ios,uiimagepickercontroller,Ios,Uiimagepickercontroller,我也曾在类似的问题中寻找答案,但我尝试过的都没有成功。当我点击叠加视图中的任意一个按钮时,相机只对焦,不会触发任何动作。这是我的密码: 更新:前面的问题得到了回答-代码很好,我只是没有在testibuttonresponses方法中提醒自己。现在我想知道如何关闭相机并在UIImageView中显示捕获的图片 此外,UIImageView*DisplayedPhoto是在IB中制作的,因此它有一个框架 @interface CameraViewController () @property UII

我也曾在类似的问题中寻找答案,但我尝试过的都没有成功。当我点击叠加视图中的任意一个按钮时,相机只对焦,不会触发任何动作。这是我的密码:

更新:前面的问题得到了回答-代码很好,我只是没有在testibuttonresponses方法中提醒自己。现在我想知道如何关闭相机并在UIImageView中显示捕获的图片

此外,UIImageView*DisplayedPhoto是在IB中制作的,因此它有一个框架

@interface CameraViewController ()
@property UIImagePickerController *PickerController;
@property (weak, nonatomic) IBOutlet UIImageView *DisplayedPhoto;
@end


- (UIView *)createCustomOverlayView
{

    // Main overlay view created
    UIView *main_overlay_view = [[UIView alloc] initWithFrame:self.view.bounds];

    // Clear view (live camera feed) created and added to main overlay view
    // ------------------------------------------------------------------------
    UIView *clear_view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - self.HeightOfButtons)];
    clear_view.opaque = NO;
    clear_view.backgroundColor = [UIColor clearColor];
    [main_overlay_view addSubview:clear_view];
    // ------------------------------------------------------------------------


    // Creates the buttons on the bottom of the view (on top of the live camera feed)
    // Then adds the buttons to the main overlay view
    // ------------------------------------------------------------------------
    for(int i = 0; i < 2; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        // when a button is touched, UIImagePickerController snaps a picture
        [button addTarget:self action:@selector(testIfButtonResponds) forControlEvents:UIControlEventTouchUpInside];
        button.frame = CGRectMake( i * self.view.frame.size.width / 2, self.view.frame.size.height - self.HeightOfButtons, self.view.frame.size.width / 2, self.HeightOfButtons);
        [button setBackgroundColor:[UIColor redColor]];
        [main_overlay_view addSubview:button];
    }
    // ------------------------------------------------------------------------

    return main_overlay_view;
}

- (void)makeCustomCameraAppear
{
    self.PickerController = [[UIImagePickerController alloc] init];
    self.PickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.PickerController.showsCameraControls = NO;
    self.PickerController.delegate = self;

    UIView *overlay_view = [self createCustomOverlayView];
    [self.PickerController setCameraOverlayView:overlay_view];

    [self presentViewController:self.PickerController animated:YES completion:NULL];
}

- (void)viewDidAppear:(BOOL)animated
{
    [self makeCustomCameraAppear];
}

- (void) testIfButtonResponds
{
    [self.PickerController takePicture];
    [self.PickerController dismissViewControllerAnimated:YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *chosen_image = info[UIImagePickerControllerEditedImage];
    self.DisplayedPhoto.image = chosen_image;
    [self.PickerController dismissViewControllerAnimated:YES completion:NULL];
}
@interface-CameraViewController()
@属性UIImagePickerController*PickerController;
@属性(弱,非原子)IBUIImageView*DisplayedPhoto;
@结束
-(UIView*)创建自定义覆盖视图
{
//已创建主覆盖视图
UIView*main_overlay_view=[[UIView alloc]initWithFrame:self.view.bounds];
//创建并添加到主覆盖视图的清除视图(实时摄影机馈送)
// ------------------------------------------------------------------------
UIView*clear_view=[[UIView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height-self.HeightOfButtons)];
clear_view.不透明=否;
clear_view.backgroundColor=[UIColor clearColor];
[主覆盖视图添加子视图:清除视图];
// ------------------------------------------------------------------------
//在视图底部(实时摄影机提要顶部)创建按钮
//然后将按钮添加到主覆盖视图中
// ------------------------------------------------------------------------
对于(int i=0;i<2;i++){
UIButton*button=[UIButton button类型:UIButtonTypeCustom];
//触摸按钮时,UIImagePickerController会捕捉图片
[按钮添加目标:自我操作:@selector(TestifButtonResponses)forControlEvents:UIControlEventTouchUpInside];
button.frame=CGRectMake(i*self.view.frame.size.width/2,self.view.frame.size.height-self.HeightOfButtons,self.view.frame.size.width/2,self.HeightOfButtons);
[按钮设置背景颜色:[UIColor REDCLOR]];
[主覆盖视图添加子视图:按钮];
}
// ------------------------------------------------------------------------
返回主覆盖视图;
}
-(无效)使CustomCamera出现
{
self.PickerController=[[UIImagePickerController alloc]init];
self.PickerController.sourceType=UIImagePickerControllerSourceTypeCamera;
self.PickerController.showsCameraControls=否;
self.PickerController.delegate=self;
UIView*overlay_view=[self-createCustomOverlayView];
[self.PickerController setCameraOverlayView:覆盖视图];
[self-presentViewController:self.PickerController动画:是完成:空];
}
-(无效)视图显示:(BOOL)动画
{
[自行制作自定义摄像机];
}
-(无效)测试按钮响应
{
[self.PickerController拍摄照片];
[self.PickerController dismissViewControllerAnimated:YES完成:nil];
}
-(void)imagePickerController:(UIImagePickerController*)picker未使用信息完成PickingMediaWithInfo:(NSDictionary*)信息
{
UIImage*所选图像=信息[UIImagePickerControllerEditedImage];
self.DisplayedPhoto.image=所选图片;
[self.PickerController dismissViewControllerAnimated:是完成:NULL];
}

您可以发布方法的代码:
testibuttonresponses
?它被调用了吗?啊,你是对的,它被调用了,但我的方法没有提醒我。谢谢我仍然无法使用其中一个按钮拍照,因此我将更新代码以显示我正在尝试的内容。只需更新
imagePickerController:didFinishPickingMediaWithInfo
中的代码,您必须执行
[自我解除视图控制器:是完成:无],而不是[self.PickerController。。。