【问题标题】:Dismissing UIImagePickerController关闭 UIImagePickerController
【发布时间】:2009-10-08 23:59:46
【问题描述】:

我有以下代码:

SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setCameraOverlayView:secondView.view];
[imagePicker setShowsCameraControls:NO];

[self presentModalViewController:imagePicker animated:YES];

我的问题是:如何从“SecondViewController”中关闭 ModalViewController?

【问题讨论】:

    标签: iphone uiimagepickercontroller iphone-sdk-3.1


    【解决方案1】:

    您必须通过secondView 中的UIImagePickerControllerDelegate 方法在imagePicker 上调用以下内容。

    例如:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        // process message
        [imagePicker dismissModalViewControllerAnimated:YES];
    }
    

    【讨论】:

    • 几乎; secondView.view 是叠加层,而不是委托,您还需要将图像选择器的委托设置为 secondView。
    • 旁注: dismissModalViewControllerAnimated: 现在在 iOS6 中已弃用
    【解决方案2】:

    已接受的答案在 iOS7 中不再有效。下面是应该使用的方法。

    同样,应该从UIImagePickerControllerDelegateUIImagePicker 调用此方法。

    -(void) imagePickerController:(UIImagePickerController *)picker
                 didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        [[picker presentingViewController] dismissViewControllerAnimated:YES completion:NULL];
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多