如何在自定义视图中添加UIImagePickerController?

时间:2013-11-18 10:19:22

标签: ios iphone objective-c uiimagepickercontroller

如何在视图中添加UIImagePickerController?如果我将图像选择器添加到视图中,则会在全屏幕上显示。我需要在视图的中心显示,但是UIImagePickerController会隐藏导航栏。

如何在视图中添加UIImagePickerController并显示导航栏?

我使用以下代码,我得到了这样的输出(截图)。

imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
imagePicker.showsCameraControls     = NO;
imagePicker.navigationBarHidden     = NO;
imagePicker.toolbarHidden           = YES;
imagePicker.wantsFullScreenLayout   = NO;
imagePicker.delegate                = self;
imagePicker.cameraOverlayView       = cameraOverlayView;
[self presentViewController:imagePicker animated:NO completion:nil];

我需要一些用于显示导航栏,同时在视图中添加UIImagePickerController。在此先感谢。enter image description here

2 个答案:

答案 0 :(得分:1)

如果您正在为iPad开发应用程序,那么您可以使用popoverviewcontroller来显示带导航栏的imagepickerviewcontroller

请看链接:

How to use UIImagePickerController in iPad?

答案 1 :(得分:1)

使用资产库自定义媒体捕获here的正确方法。

简单方法(在某些情况下)使用覆盖视图与整个屏幕的帧大小,并在该视图上添加模拟导航栏的控件。

    if (_pickerOverlay == nil) {
    _pickerOverlay = [[UIView alloc] initWithFrame:self.view.bounds];
    //red transparent tint for demo
    _pickerOverlay.backgroundColor = [UIColor colorWithRed:1.0
                                                     green:0.0
                                                      blue:0.0 alpha:0.6];

    UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeSystem];
    btnBack.frame = CGRectMake(20, 20, 250, 40);
    [btnBack setTitle:@"Custom buttom" forState:UIControlStateNormal];
    btnBack.backgroundColor = [UIColor whiteColor];
    [_pickerOverlay addSubview:btnBack];
}

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.cameraOverlayView = _pickerOverlay;

[self presentViewController:picker animated:YES completion:nil];