ios - UIImagePickerController 不在 iOS 8 中呈现

标签 ios ipad uiimagepickercontroller ios8

还有其他人在 iOS 8 中遇到 UIImagePickerController 问题吗?下面的方法在 iPad 上的 iOS 7 中运行得非常好,但是当我在 XCode 6(Beta 3 或 4)中运行它时,当我尝试显示选择器(最后一行)时出现以下错误。如果重要的话,sourceType 的选择来自显示在同一位置的 alertView。

Warning: Attempt to present <UIImagePickerController: 0x7c0ae400>  on <CAGUCreateContactViewController: 0x7bf61a00> which is already presenting (null)

打开图片选择器的方法。

- (void)openPhotoPicker:(UIImagePickerControllerSourceType)sourceType
{
    if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
        NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
        if ([availableMediaTypes containsObject:(NSString *)kUTTypeImage]) {
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
            imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
            imagePickerController.sourceType = sourceType;
            imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
            imagePickerController.delegate = self;

            self.imagePickerController = imagePickerController;

            if (sourceType == UIImagePickerControllerSourceTypeCamera) {
                [self presentViewController:self.imagePickerController animated:YES completion:nil];
            } else {                    
                if (self.popoverVC) {
                    [self.popoverVC dismissPopoverAnimated:YES];
                    self.popoverVC = nil;
                }

                self.popoverVC = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
                [self.popoverVC presentPopoverFromRect:self.nameAndPicCell.picture.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
            }
        }
    }
}

最佳答案

我认为这是因为在 iOS 8 中,警报 View 和操作表实际上是呈现的 View Controller (UIAlertController)。因此,如果您要呈现一个新的 View Controller 以响应来自 UIAlertView 的操作,它会在 UIAlertController 被关闭时呈现。我通过将 UIImagePickerController 的呈现延迟到运行循环的下一次迭代来解决这个问题,方法是:

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    [self openPhotoPicker:sourceType];
}];

但是,解决此问题的正确方法是在 iOS 8 上使用新的 UIAlertController API(即使用 if ([UIAlertController class]) ... 来测试为了它)。如果您还不能使用新的 API,这只是一种解决方法。

关于ios - UIImagePickerController 不在 iOS 8 中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24942282/

相关文章:

ios - 从左到右将 UIView 移出屏幕并从左再次将其移入

ios - 我可以释放添加到NSMutableArray中的对象吗?这会导致崩溃吗?

iphone - subview 内的 touchesMoved 检测

objective-c - iOS:使用相机时放大到屏幕的一部分

ios - 如何从 Swift 3 中的闭包返回

android - 统计签到次数

ios - 我可以使用什么服务在 IOS 上快速发送推送通知

iphone - 将变量从一个 View 转移到另一个 View

UIImagePickerController 返回错误的图像方向

ios - WhatsApp 如何将 UIImagePickerController 推送到导航 Controller 堆栈?