UIImagePickerController没有在iOS 8中呈现 [英] UIImagePickerController not presenting in iOS 8
问题描述
其他人在iOS 8中遇到 UIImagePickerController
的问题吗?下面的方法在iPad上的iOS 7中运行得非常好,但是当我尝试呈现选择器(最后一行)时,我在XCode 6(Beta 3或4)中运行时会出现以下错误。如果重要,sourceType的选择来自同一地点的alertView。
Is anyone else having an issue with UIImagePickerController
in iOS 8? The method below works perfectly well in iOS 7 on an iPad, but I get the following error when I run this in XCode 6 (Beta 3 or 4) when I try to present the picker (last line). If it matters, the selection of the sourceType is coming from an alertView that is presented in the same place.
Warning: Attempt to present <UIImagePickerController: 0x7c0ae400> on <CAGUCreateContactViewController: 0x7bf61a00> which is already presenting (null)
打开imagePicker的方法。
Method to open imagePicker.
- (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中,警报视图和操作表实际上是视图控制器( UIAlertController
)。因此,如果您要呈现一个新的视图控制器以响应 UIAlertView
中的操作,那么它将在 UIAlertController $ c $时显示c>正在被解雇。我通过延迟
UIImagePickerController
的演示来解决这个问题,直到runloop的下一次迭代,通过这样做:
I think this is because in iOS 8, alert views and action sheets are actually presented view controllers (UIAlertController
). So, if you're presenting a new view controller in response to an action from the UIAlertView
, it's being presented while the UIAlertController
is being dismissed. I worked around this by delaying the presentation of the UIImagePickerController
until the next iteration of the runloop, by doing this:
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self openPhotoPicker:sourceType];
}];
但是,解决这个问题的正确方法是使用新的 UIAlertController
iOS 8上的API(即使用 if([UIAlertController class])
...来测试它)。如果您尚未使用新API,这只是一种解决方法。
However, the proper way to fix this is to use the new UIAlertController
API on iOS 8 (i.e. use if ([UIAlertController class])
... to test for it). This is just a workaround if you can't use the new API yet.
这篇关于UIImagePickerController没有在iOS 8中呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!