iOS 8 SDK:模态UIWebView和相机/图像选择器 [英] iOS 8 SDK: modal UIWebView and camera/image picker
问题描述
我发现,在编译iOS 8(并在iOS 8中运行)时,如果 UIWebView
无法显示相机/图像选择器> UIWebView 位于以模态方式呈现的视图控制器中。它在视图控制器中直接从窗口悬挂 rootViewController
或查看从它推出的控制器时没有问题。
I have found that, when compiling for iOS 8 (and running in iOS 8), a UIWebView
cannot show the camera/image picker if the UIWebView
is in a view controller presented modally. It works without problem in view controllers directly "hanging" from the window rootViewController
or view controllers pushed from it.
测试应用程序可在 https://dl.dropboxusercontent.com/u/6214425/TestModalWebCamera.zip找到a>但我将在下面对其进行描述。
The test application can be found at https://dl.dropboxusercontent.com/u/6214425/TestModalWebCamera.zip but I will describe it below.
我的测试应用程序(使用故事板构建,但实际应用程序不使用它们)有两个视图控制器(非原始命名为 ViewController
和 ViewController2
)。 ViewController
包含在 UINavigationController
中,它是根视图控制器。 ViewController
包含 UIWebView
(工作正常),一个显示(推)<$ c $的按钮c> ViewController2 ,以及一个 UIBarButtonItem
,它以模态方式呈现 ViewController2
。 ViewController2
还有另一个 UIWebView
,它在推送时有效,但在显示时无效。
My test application (built with storyboards, but the real application doesn’t use them) has two view controllers (unoriginally named ViewController
and ViewController2
). ViewController
is contained in a UINavigationController
which is the root view controller. ViewController
contains a UIWebView
(works OK), a button that "shows" ("pushes") ViewController2
, and a UIBarButtonItem
which modally presents ViewController2
. ViewController2
has another UIWebView
which works when "pushed" but not when "presented".
ViewController
和 ViewController2
都加载了:
- (void)viewDidLoad {
[super viewDidLoad];
[self.webView loadHTMLString:@"<input type=\"file\" accept=\"image/*;capture=camera\">" baseURL:nil];
}
尝试使用模态时 UIWebView
Xcode在控制台中打印以下内容并解除应用模式:
When trying to use the modal UIWebView
Xcode prints the following in the console and dismisses the app modal:
Warning: Attempt to present <UIImagePickerController: 0x150ab800> on <ViewController2: 0x14623580> whose view is not in the window hierarchy!
我目前的理论是 UIActionSheet的变化
到 UIAlertController
可能产生了这种情况,但很难证明。为了以防万一,我将用Apple打开雷达。
My current theory is that the changes in UIActionSheet
to UIAlertController
might have produced this situation, but it’s quite hard to prove. I will open a Radar with Apple, just in case.
有人发现了同样的情况和一些解决方法吗?
Has someone found the same situation and some workaround?
推荐答案
我发现在iOS 8.0.2中iPad似乎没有那个bug,但iPhone仍然存在。
I found that in iOS 8.0.2 iPad does not seem to have that bug but iPhone still does.
但是,在包含uiwebview的视图控制器中覆盖以下内容
However, overriding following in the view controller containing the uiwebview
-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
并检查是否有一个presentViewController似乎工作。
And checking that there is a presentedViewController seems to work.
但需要检查副作用
#import "UiWebViewVC.h"
@interface UiWebViewVC ()
@property (weak, nonatomic) IBOutlet UIWebView *uiwebview;
@end
@implementation UiWebViewVC
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://html5demos.com/file-api-simple"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
self.uiwebview.scalesPageToFit = YES;
[self.uiwebview loadRequest:request];
}
-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
if ( self.presentedViewController)
{
[super dismissViewControllerAnimated:flag completion:completion];
}
}
@end
这篇关于iOS 8 SDK:模态UIWebView和相机/图像选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!