XHLaunchAd icon indicating copy to clipboard operation
XHLaunchAd copied to clipboard

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

Open Yck-Dakucha opened this issue 5 years ago • 5 comments

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

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

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

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

Yck-Dakucha avatar Aug 12 '20 07:08 Yck-Dakucha

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

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

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

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

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

DotaAntiMagic avatar Jun 22 '21 03:06 DotaAntiMagic

大哥们问题解决了吗

indulgeIn avatar Sep 17 '21 11:09 indulgeIn

大哥们问题解决了吗

使用分类重写了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 `

Yck-Dakucha avatar Sep 17 '21 12:09 Yck-Dakucha

就很神奇,这是为什么呢? 今天前端和我反馈了这个问题,开始以为是前端的问题,后来试了下 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

LisonFan avatar Jan 25 '22 16:01 LisonFan

我的项目中使用了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 ,不过确实会造成页面内其他动画卡顿,不知道老哥有啥好的方案吗

Commandercc avatar Aug 13 '22 13:08 Commandercc