CoderZhuXH / XHLaunchAd

🔥The screen opening advertising solutions - 开屏广告、启动广告解决方案-支持静态/动态图片广告,mp4视频广告,全屏/半屏广告、兼容iPhone/iPad. 【 Github下载不了/下载慢 可以访问国内下载地址: https://gitee.com/CoderZhuXH/XHLaunchAd】

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

3.9.12 XHLaunchImageView imageFromView导致WKWebView 页面一些CSS和Video标签工作异常

Yck-Dakucha opened this issue · comments

我的项目中使用了WKWebView,使用新版后发下一些页面的css异常,异常情况有

  1. css transition动画异常,滑动时间0.3秒 实际为0.1秒
  2. Vidoe标签 窗口播放视频卡顿

排查后主要影响方法的是
drawViewHierarchyInRect: afterScreenUpdates:
afterScreenUpdates为YES时

afterScreenUpdate设置为NO 或者使用 renderInContext 就工作正常

我的项目中使用了WKWebView,使用新版后发下一些页面的css异常,异常情况有

  1. css transition动画异常,滑动时间0.3秒 实际为0.1秒
  2. Vidoe标签 窗口播放视频卡顿

排查后主要影响方法的是
drawViewHierarchyInRect: afterScreenUpdates:
afterScreenUpdates为YES时

afterScreenUpdate设置为NO 或者使用 renderInContext 就工作正常

我也出现了这样的情况了,这个会让前端的滑动动画变动很卡顿,请问下你后来是怎么解决的,注释掉[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES]吗?

大哥们问题解决了吗

大哥们问题解决了吗

使用分类重写了imageFromView

`#import "XHLaunchImageView+imageFromViewFix.h"

@implementation XHLaunchImageView (imageFromViewFix)

  • (UIImage *)imageFromView:(UIView *)view {
    if (CGRectIsEmpty(view.frame)) {
    return nil;
    }
    UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, [UIScreen mainScreen].scale);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:context];
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
    }

@EnD
`

就很神奇,这是为什么呢?
今天前端和我反馈了这个问题,开始以为是前端的问题,后来试了下 Chrome 和微信,发现都是正常的,然后找到了这个帖子
就很好奇是什么原因导致的,为什么调用 drawViewHierarchyInRect: afterScreenUpdates: 会导致前端动画卡顿
现在已经是 iOS 15.2.1

网上搜索的时候还找到了 http://blog.startry.com/2016/02/24/Screenshots-With-SwViewCapture/ 这篇文章,早在 Chrome 46.0.2478.0 版本的代码中就提到了这个问题 https://chromium.googlesource.com/chromium/src.git/+/46.0.2478.0/ios/chrome/browser/snapshots/snapshot_manager.mm

我的项目中使用了WKWebView,使用新版后发下一些页面的css异常,异常情况有

  1. css transition动画异常,滑动时间0.3秒 实际为0.1秒
  2. Vidoe标签 窗口播放视频卡顿

排查后主要影响方法的是 drawViewHierarchyInRect: afterScreenUpdates: afterScreenUpdates为YES时

afterScreenUpdate设置为NO 或者使用 renderInContext 就工作正常

大哥们问题解决了吗

使用分类重写了imageFromView

`#import "XHLaunchImageView+imageFromViewFix.h"

@implementation XHLaunchImageView (imageFromViewFix)

  • (UIImage *)imageFromView:(UIView *)view {
    if (CGRectIsEmpty(view.frame)) {
    return nil;
    }
    UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, [UIScreen mainScreen].scale);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:context];
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
    }

@EnD `

大哥 这个如果用renderInContext的话,webView上的一些比如css做的特殊效果,截屏的时候就截不到,还是得用drawViewHierarchyInRect ,不过确实会造成页面内其他动画卡顿,不知道老哥有啥好的方案吗