Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the cancel button from Custom camera

I am using a custom overlay frame, on camera. On the navigation bar I have app icon in the middle and a back button on left.

So I would like to remove the default cancel button besides the capture button but I do not want to remove camera click button. I have done research but I did not find a perfect answer. I have already used the following code but it also removes the click button.

[picker setShowsCameraControls:YES];
like image 401
Darshan Karekar Avatar asked Sep 14 '15 12:09

Darshan Karekar


2 Answers

I feel you you should add custom CameraOverlayView to your uiimagepickercontroller and hide CameraControls.This won’t show your cancel button.

 picker = [[UIImagePickerController alloc] init];                
 picker.delegate = self;
 picker.sourceType = UIImagePickerControllerSourceTypeCamera;
 [picker setShowsCameraControls:NO];
 CGRect screenBounds= [UIScreen mainScreen].bounds ;
 UIView *overlayView = [[UIView alloc] initWithFrame:screenBounds];
 [overlayView setAutoresizesSubviews:YES];
 [overlayView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin]; UIButton *captureButton=[[UIButton alloc]initWithFrame:CGRectMake(screenBounds.size.width/2-30, screenBounds.size.height-60,60 , 60)];
[captureButton addTarget:self action:@selector(captureImage:) forControlEvents:UIControlEventTouchUpInside];
[captureButton setBackgroundImage:[UIImage imageNamed:@"icon"] forState:UIControlStateNormal];
[overlayView addSubview:captureButton];
[picker setCameraOverlayView:overlayView];
[picker setCameraDevice:UIImagePickerControllerCameraDeviceRear];                
[self presentViewController:picker animated:YES completion:NULL];

And this is action for Capture button.

-(void)captureImage:(UIButton*)sender
{
[picker takePicture];
}

And use this delegate method to get image.

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}
like image 83
Deepesh Avatar answered Oct 08 '22 11:10

Deepesh


I think you disable but about removing i am not sure as I know it is not possible because UIImagePickerController inherits UINavigationController. Then you can get

UINavigationBar *bar = picker.navigationBar;
[bar setHidden:NO];
bar.navigationItem.rightBarButtonItem = doneButton;

It will work only for IOS 6

You can use this source ELCImagePickerController

like image 25
Grigori Jlavyan Avatar answered Oct 08 '22 12:10

Grigori Jlavyan