iOS:在 UIWebView 顶部显示模式视图
是否可以在 UIWebView 顶部显示模式视图?我有一个加载 WebView 的 UIViewController。然后我想将模态视图控制器推到顶部,以便模态视图暂时覆盖 WebView...
WebView 工作正常;这是它在视图控制器中的加载方式:
- (void)loadView {
// Initialize webview and add as a subview to LandscapeController's view
myWebView = [[[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
myWebView.scalesPageToFit = YES;
myWebView.autoresizesSubviews = YES;
myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
myWebView.delegate = self;
self.view = myWebView;
}
但是,如果我尝试从 viewDidLoad 中加载模态视图控制器,则不会出现模态视图:
- (void)viewDidLoad {
[super viewDidLoad];
// Edit dcftable.html with updated figures
NSMutableString *updated_html = [self _updateHTML:@"dcftable"];
// Load altered HTML file as an NSURL request
[self.myWebView loadHTMLString:updated_html baseURL:nil];
// If user hasn't paid for dcftable, then invoke the covering modal view
if (some_condition) {
LandscapeCoverController *landscapeCoverController = [[[LandscapeCoverController alloc] init] autorelease ];
[self presentModalViewController:landscapeCoverController animated:YES];
}
}
我怀疑需要对 UIWebView 委托执行一些操作才能使其接收新的模态视图...但在任何地方都找不到任何讨论或示例...同样,目标是调用覆盖 WebView 顶部的模态视图。
感谢您提前提出任何想法!
Is it possible to display a modal view over the top of a UIWebView? I have a UIViewController that loads a WebView. I then want to push a Modal View Controller over the top so that a modal view covers up the WebView temporarily...
The WebView is working fine; here's how it's loaded in the View Controller:
- (void)loadView {
// Initialize webview and add as a subview to LandscapeController's view
myWebView = [[[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
myWebView.scalesPageToFit = YES;
myWebView.autoresizesSubviews = YES;
myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
myWebView.delegate = self;
self.view = myWebView;
}
If I attempt to load a Modal View controller from within viewDidLoad, however, no modal view appears:
- (void)viewDidLoad {
[super viewDidLoad];
// Edit dcftable.html with updated figures
NSMutableString *updated_html = [self _updateHTML:@"dcftable"];
// Load altered HTML file as an NSURL request
[self.myWebView loadHTMLString:updated_html baseURL:nil];
// If user hasn't paid for dcftable, then invoke the covering modal view
if (some_condition) {
LandscapeCoverController *landscapeCoverController = [[[LandscapeCoverController alloc] init] autorelease ];
[self presentModalViewController:landscapeCoverController animated:YES];
}
}
I suspect that there's something that needs to be done with the UIWebView delegate to get it to receive the new modal view...but can't find any discussion or examples of this anywhere...again, the objective is to invoke a modal view that covers over the top of the WebView.
Thanks for any thoughts in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题。将
presentModalViewController
调用从viewDidLoad
移动到viewDidAppear
就成功了。I ran into this same problem. Moving the
presentModalViewController
call fromviewDidLoad
toviewDidAppear
did the trick.我也无法让它在 viewDidLoad 中工作,但我让它以不同的方法工作。这就是我所做的:
基本上,如果没有在
viewDidLoad
中调用它,它就会起作用。我希望我能解释为什么,我自己很好奇,但这至少应该解决你的问题。希望这有帮助!
I couldn't get it to work in
viewDidLoad
either, but I got it to work in a different method. Here's what I did:Basically, it works if it's not being called in
viewDidLoad
. I wish I could explain why, I'm curious myself, but this should at least fix your problem.Hope this helps!