我有一个播放 youtube 视频的 uiwebview。如何处理完成按钮操作? 现在,当我点击完成按钮时,它会变回我的应用程序主菜单(不是应该关闭的菜单)并且它只是卡住。谁能帮帮我?
Ps:uiwebview所在的菜单,之前是模态呈现的。
最佳答案
YouTube 插件播放器本身就是一个模态视图 Controller 。当完成按钮被按下时,它返回到它的 presentingViewController
。它的 presentingViewController
不是模态视图 Controller ,而是调用 [presentModalViewController:animated:]
来呈现模态视图 Controller 的 viewController。由于原始模态视图 Controller 仍处于事件状态,因此该应用的行为很糟糕。
为了解决这个问题,
1) 跟踪模态视图 Controller 是否已呈现但未被关闭。
2) 在呈现 View Controller 的 viewDidAppear
方法中,如果模态视图 Controller 已呈现且未被解除,则解除并再次呈现。
例如,在呈现模态 Web View Controller 的 Controller 中:
- (void) presentModalWebViewController:(BOOL) animated {
// Create webViewController here.
[self presentModalViewController:webViewController animated:animated];
self.modalWebViewPresented = YES;
}
- (void) dismissModalWebViewController:(BOOL) animated {
self.modalWebViewPresented = NO;
[self dismissModalViewControllerAnimated:animated];
}
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (self.modalWebViewPresented) {
// Note: iOS thinks the previous modal view controller is displayed.
// It must be dismissed first before a new one can be displayed.
// No animation is needed as the YouTube plugin already provides some.
[self dismissModalWebViewController:NO];
[self presentModalWebViewController:NO];
}
}
关于iphone - 在 uiwebview 中播放 youtube 视频。如何处理 "done"按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8419145/