Ios 自定义UIImagePickerController视图不工作

Ios 自定义UIImagePickerController视图不工作,ios,uiimagepickercontroller,Ios,Uiimagepickercontroller,我正在尝试在我的视图控制器中制作一个自定义图像选择器(相机) 代码如下: - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Instantiate the UIImagePicke

我正在尝试在我的视图控制器中制作一个自定义图像选择器(相机)

代码如下:

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Instantiate the UIImagePickerController instance
        self.picker = [[UIImagePickerController alloc] init];

        // Configure the UIImagePickerController instance
        self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
        self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
        self.picker.showsCameraControls = NO;

        // Make us the delegate for the UIImagePickerController
        self.picker.delegate = self;

        // Set the frames to be full screen
        CGRect screenFrame = [[UIScreen mainScreen] bounds];
        self.view.frame = screenFrame;
        self.picker.view.frame = screenFrame;

        // Set this VC's view as the overlay view for the UIImagePickerController
        self.picker.cameraOverlayView = self.view;
    }
    return self;
}
我有一个黑色页面,上面有我创建的按钮,除此之外什么都没有。当我按下拍照按钮时,它确实拍了一张真实的照片。 所以我的问题是UIImagePicker没有在我的视图上显示相机捕获

谁能帮我一下吗。
提前感谢。

请确保在拍摄图像后使用正确的委托方法来显示图像。大概是这样的:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *myPhotoData = [[NSData alloc] init];
myPhotoData = UIImageJPEGRepresentation(image, 0.5); // compressionQuality between 0.0 and 1.0 higher being less compression
myPhotoOutlet.image = [UIImage imageWithData:myPhotoData]; // myPhotoOutlet is an UIImageView outlet on your screen
[self dismissViewControllerAnimated:YES completion:nil];
}

您必须在.h文件中添加一个委托声明:

@interface YourViewcontroller : UIViewController <UIImagePickerControllerDelegate>

我希望这对你有帮助

我已经做了!我的问题是当我将VC视图设置为UIImagePickerController的覆盖时。我得到了没有UiImagePickerController的VC视图。所以当我停用这个时,UIImagePickeControl像往常一样工作。我已经做了!我的问题是当我将VC视图设置为UIImagePickerController的覆盖时。我得到了没有UiImagePickerController的VC视图。因此,当我停用此功能时,UIImagePickerController将正常工作。
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    UIImage *newImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    // and then you affect your image in your image view
   UIImageView *yourImageView= [[UIImageView alloc] initWithFrame:CGRectMake(0,0,300,300)];
   yourImageView.image=newImage;
}