我尝试制作WKWebView的截图是OS X应用程序,并获得完全空的截图。此代码适用于原始WebView,但不适用于WKWebView。
NSView *view = webView;
NSRect bounds = [view bounds];
NSBitmapImageRep *bitmapdata = [view bitmapImageRepForCachingDisplayInRect: bounds];
[webView cacheDisplayInRect: bounds toBitmapImageRep: bitmapdata];
任何想法如何解决?
答案 0 :(得分:1)
现在,您可以使用WKWebView
来截取屏幕截图。
//iOS
func takeSnapshot(with snapshotConfiguration: WKSnapshotConfiguration?,
completionHandler: @escaping (UIImage?, Error?) -> Void)
//macOS
func takeSnapshot(with snapshotConfiguration: WKSnapshotConfiguration?,
completionHandler: @escaping (NSImage?, Error?) -> Void)
但它还处于测试阶段。