0

I have searched similar questions for answers, but nothing I have tried has worked. When I tap on either button in my overlay view, the camera only focuses - no action is triggered. Here is my code:

Update: The previous question was answered - the code was fine, I just wasn't alerting myself in the testIfButtonResponds method. Now I am wondering how to dismiss the camera and show the captured picture in a UIImageView.

Also, the UIImageView *DisplayedPhoto was made in IB, so it has a frame.

@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];
}
4
  • Can you post the code of the method: testIfButtonResponds? Does it get called? Commented Jul 23, 2014 at 21:24
  • Ah, you are right, it was getting called but my method wasn't alerting me. Thanks! I am still having trouble taking a picture with one of the buttons, so I am going to update my code to show what I'm trying. Commented Jul 23, 2014 at 21:53
  • Just updated the code Commented Jul 23, 2014 at 22:02
  • In imagePickerController:didFinishPickingMediaWithInfo you have to do [self dismissViewControllerAnimated:YES completion:nil];, not [self.PickerController... Commented Jul 24, 2014 at 4:06

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.