0

我有一个关于 UIImagePickerController 的问题。我可以使用 UIImagePickerController 作为预览吗?如果我这样做,我必须隐藏记录按钮,有什么办法吗?或除 UIImagePickerController 之外的任何其他显示预览的方法。

感谢您的帮助...

4

1 回答 1

3

您可以使用以下方法隐藏 a 的控件UIImagePickerController

[myImagePickerController setShowsCameraControls:NO];

编辑:查看此代码,它隐藏了图像选择器内的所有控件,允许您创建和添加自己的自定义控件。不幸的是,您不能有选择地隐藏选择器中的控件,因此这是替代方法。

- (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];
    }
}
于 2012-09-07T07:26:33.340 回答