视频播放
1.使用H5进行视频播放且自动使用系统播放器,在全屏变为小屏,并返回上个界面的时候,出现视频声音没有关闭的情况。
解决办法:
让webview调用一个 about:blank的url。就可以停止视频播放。
-(void) viewDidDisappear:(BOOL)animated
{
NSLog(@"媒体打开窗口被隐藏");
[webViewer loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
}
H5界面过长,滑动流畅,在点击菜单滑动到指定位置的时候,出现白屏,需要滑动,才能显示内容的时候。
解决办法:
http://www.jianshu.com/p/171b8b7761cb
可以判断是否使用了UIWebOverflowScrollView,给webVIew添加点击手势,在点击方法中,对scrollView进行重新布局。代码如下:
//增加手势 解决白屏问题
UITapGestureRecognizer *myTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[self.testWeb addGestureRecognizer:myTap];
myTap.delegate = self;
myTap.cancelsTouchesInView = NO;
//手势方法
-(void)handleSingleTap:(UITapGestureRecognizer *)sender{
CGPoint gesturePoint = [sender locationInView:self.view];
NSLog(@"handleSingleTap!gesturePoint:%f,y:%f",gesturePoint.x,gesturePoint.y);
UIView *scrollView = self.testWeb;
while ([scrollView.subviews count]) {
scrollView = scrollView.subviews[0];
if ([scrollView isMemberOfClass:NSClassFromString(@"UIWebOverflowScrollView")]) {
CGRect frame = scrollView.superview.frame;
frame.origin.x = 0;
scrollView.frame = frame;
break;
}
}
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
当使用webView与H5进行交互的时候,出现传递多个参数的情况,使用JSExportAs
解决方法
例子如下:
JSExportAs(onJSInvokeResult, - (void)onJSInvokeResult:(NSInteger)type Result:(NSString*)title);
WKWebView与原生交互
http://www.cnblogs.com/jiang-xiao-yan/p/5345893.html
使用
window.webkit.messageHandlers.<name>.postMessage(<messageBody>)
来定义方法调用
UIWebView去除系统复制粘贴功能
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// Disable user selection
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
// Disable callout
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];}
[reason:accessing _cachedSystemAnimationFence requires the main thread 需要访问主线程]
问题出现的可能
在输入法弹出的情况下,点击按钮调用js方法,进行拍照,可能在子线程中进行调用,从而出现上述错误,需要放到主线程中进行调用
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.WebViewController self.pickController animated:YES completion:NULL];
});
dispatch_async(dispatch_get_main_queue(), ^{
[picker dismissViewControllerAnimated:YES completion:^{
// 改变状态栏的颜色 改变为白色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}];
});