H5与原生交互的坑

视频播放

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..postMessage()

来定义方法调用

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];
    }];
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值