关闭imagepickercontroller

时间:2014-05-19 20:45:14

标签: ios uiimagepickercontroller viewcontroller

我正在尝试解雇一个imagepickercontroller(相册或相机),如下所示

    [self.view.window.rootViewController presentViewController:imagePicker animated:YES completion:nil];

致电:

     [self dismissViewControllerAnimated:YES completion:NULL];

我无法解雇imagepickercontroller。

任何人都能帮助我吗?

2 个答案:

答案 0 :(得分:1)

我用这个:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    [self dismissViewControllerAnimated:YES completion:nil];
else
    [popover dismissPopoverAnimated:YES];

不知道NULL而不是nil是否重要,但它应该是nil。

选择器显示以下代码:

- (void)getVideoFromDevice
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)  // for ipad only
    {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.allowsEditing = NO;
        imagePicker.videoQuality = UIImagePickerControllerQualityTypeLow;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];;
        popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
        [popover presentPopoverFromBarButtonItem:[self.navigationItem.rightBarButtonItems objectAtIndex:0] permittedArrowDirections: UIPopoverArrowDirectionAny animated:YES];
    }
    else    // for iphone only - NOT TESTED
    {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }
}

我尚未测试iPhone的代码,但iPad部分正常运行。

答案 1 :(得分:0)

您需要关闭委托方法中的UIImagePickerViewControllerimagePickerController: didFinishPickingMediaWithInfo:imagePickerControllerDidCancel:。请务必将UIImagePickerViewController代理人分配给提出UIViewController的{​​{1}}。

示例:

UIImagePickerViewController