Hide record button in UIImagePickerController

2019-08-17 03:49发布

问题:

I have a question on UIImagePickerController. May I use UIImagePickerController as a preview? If I do like that, I have to hide record button, is there any way to do it? or Any other approach to show our preview other than UIImagePickerController.

thanks for your helps...

回答1:

You can hide the controls of a UIImagePickerController by using:

[myImagePickerController setShowsCameraControls:NO];

EDIT: Check out this code, it hides all the controls inside the image picker allowing you to create and add your own custom controls. Unfortunately you can not selectively hide controls within the picker so this is the alternative.

- (void)showCamera
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {

        myImagePicker = [[UIImagePickerController alloc] init];

        [myImagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
        [myImagePicker setDelegate:self];
        [myImagePicker setShowsCameraControls:NO];
        UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
        UIButton *switchCameraButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [switchCameraButton setFrame:CGRectMake(10, 430, 72, 40)];
        [switchCameraButton addTarget:self action:@selector(changeCamera:) forControlEvents:UIControlEventTouchUpInside];
        [overlayView addSubview:switchCameraButton];
        [myImagePicker setCameraOverlayView:overlayView];
        [self presentViewController:myImagePicker animated:YES completion:nil];

    }
}
- (IBAction)changeCamera:(id)sender
{
    if (myImagePicker.cameraDevice == UIImagePickerControllerCameraDeviceFront) {
        [myImagePicker setCameraDevice:UIImagePickerControllerCameraDeviceRear];
    }else{
        [myImagePicker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
    }
}