Removing the cancel button from Custom camera

感情迁移 提交于 2019-12-23 07:47:27

问题


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];

回答1:


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];
}



回答2:


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



来源:https://stackoverflow.com/questions/32564813/removing-the-cancel-button-from-custom-camera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!