0

I'm trying to set up a a view that contains a button on top of UIImagePickerControllerView. I've seen it's possible to build an overlayView view setting picker.showsCameraControls = NO; and adding subview to the Overlay. But I don't want to lose the controllers, just to add a button on top. Is this possible?

Here my code:

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
    UIImagePickerController *imagePickerCam =
    [[UIImagePickerController alloc] init];
    imagePickerCam.delegate = self;
    imagePickerCam.sourceType =
    UIImagePickerControllerSourceTypeCamera;
    imagePickerCam.mediaTypes = [NSArray arrayWithObjects:
                                 (NSString *) kUTTypeMovie,
                                 nil];
    imagePickerCam.allowsEditing = NO;

    UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    UIButton *Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [Button setFrame:CGRectMake(200, 480, 80, 80)];
    [Button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
    [overlayView addSubview:Button];

    [imagePickerCam.view addSubview:overlayView];
    [overlayView bringSubviewToFront:imagePickerCam.view];

    [self presentModalViewController:imagePickerCam
                            animated:YES];
}

I'm trying this:

 [imagePickerCam.view addSubview:overlayView];
 [overlayView bringSubviewToFront:imagePickerCam.view];

Of course, it doesn't work. Any idea?

Pau Senabre
  • 4,155
  • 2
  • 27
  • 36
  • What is the result of "not working"? Could be that the internal implementation only adds views after the view is added to the hierarchy, which creates issues for your view. – Léo Natan Apr 16 '14 at 18:48
  • Why don't you add a toolbar to UIImagePickercontroller for adding buttons – Jayaprada Apr 16 '14 at 18:50
  • Well, doesn't work meaning the button doesn't show. The UIImagePickerController works fine, with the normal controls but the overlay is not added as subview. How can I add a toolbar? – Pau Senabre Apr 16 '14 at 21:01

1 Answers1

0

First thing, you should use :

[imagePickerCam setCameraOverlayView: overlayView];

This way, you won't have to manage the order of the subviews, so you can remove the line :

[overlayView bringSubviewToFront:imagePickerCam.view];

which, by the way, should have been the other way around :

[imagePickerCam.view bringSubviewToFront:overlayView];

Secondly, your overlay view has a height of 480, an you set you UIButton y offset to 480, so the button is out ouf bounds. Try something like :

UIView *overlayView = [[UIView alloc] initWithFrame:self.view.frame];
UIButton *Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[Button setFrame:CGRectMake(200, self.view.frame.size.height - 80, 80, 80)];
Emilie
  • 2,413
  • 13
  • 12
  • Nice, this worked! The button shows up, the problem now is that the normal controllers for the camera doesn't work, is like their under overlayView and don't react no more. Any idea how to solve this? – Pau Senabre Apr 16 '14 at 21:21