gpt4 book ai didi

objective-c - OS X 中的 WKWebView cacheDisplayInRect 屏幕截图

转载 作者:搜寻专家 更新时间:2023-10-30 20:24:39 25 4
gpt4 key购买 nike

我尝试制作 WKWebView 是 OS X 应用程序的屏幕截图,并得到完全空白的屏幕截图。此代码适用于原始 WebView,但不适用于 WKWebView。

NSView *view = webView;
NSRect bounds = [view bounds];

NSBitmapImageRep *bitmapdata = [view bitmapImageRepForCachingDisplayInRect: bounds];
[webView cacheDisplayInRect: bounds toBitmapImageRep: bitmapdata];

有什么解决办法吗?

最佳答案

现在您可以使用 WKWebView 截屏了。

Apple added a new method ,

//iOS
func takeSnapshot(with snapshotConfiguration: WKSnapshotConfiguration?,
completionHandler: @escaping (UIImage?, Error?) -> Void)

//macOS
func takeSnapshot(with snapshotConfiguration: WKSnapshotConfiguration?,
completionHandler: @escaping (NSImage?, Error?) -> Void)

但它仍处于测试阶段。

关于objective-c - OS X 中的 WKWebView cacheDisplayInRect 屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31969950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com