在灯光模式下获取PKDrawing的图像 [英] Get Image of PKDrawing in Light mode

查看:62
本文介绍了在灯光模式下获取PKDrawing的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的UI支持暗模式,但不希望我的PKCanvasView.我用

I want my UI to support dark mode, but not my PKCanvasView. I used

myCanvasView.overrideUserInterfaceStyle = .light

因此暗模式不适用于它,它起作用了:黑线保持黑色,白线保持白色,而UI的其余部分响应系统设置.

so the dark mode does not apply to it and it worked: Black lines stay black and white lines stay white, while the rest of the UI is responsive to the system setting.

但是,当我尝试像这样捕获PKDrawing的图像时:

However, when I try to capture an image of the PKDrawing like this:

myCanvasView.drawing.image(from: myCanvasView.bounds, scale: CGFloat(1.0))

启用暗模式时,图像上的白线变为黑色,黑线变为白色.我在所有ViewController上都将overrideUserInterfaceStyle设置为.light,但是图形的图像仍受系统设置影响.仅当在info.plist文件中覆盖用户界面Stile时,即使我在所有ViewController上将overrideUserInterfaceStyle设置为.dark

the white lines on the image change to black and black lines change to white when dark mode is active. I set overrideUserInterfaceStyle to .light on all of my ViewControllers, but the image of the drawing is still affected by the system setting. Only when overriding the User Interface Stile in the info.plist file, the image of the PKDrawing stays like I want it to be, even when I set overrideUserInterfaceStyle on all ViewControllers to .dark

是否有一种方法可以从PKDrawing中获取灯光模式"图像,而又不会覆盖info.plist文件,从而失去了响应系统设置的可能性?对我来说,似乎PKDrawing的image()函数只是检查为应用程序而不是为任何ViewController设置的用户界面样式.由于PKDrawing是一个不透明的对象,因此无法覆盖该方法.

Is there a way to get a "light mode" image from PKDrawing without overriding the info.plist file and therefore losing the possibility to respond to the system setting? To me it seems like the image() function of PKDrawing just checks User Interface Style that is set for the app and not for any ViewControllers. Overriding the method won't work since PKDrawing is an opaque object.

我的想法是重写info.plist中应用程序的界面样式,然后检查系统设置,并根据设置为所有ViewController设置界面样式.这将使图形的图像像应该的那样正常,但保持对系统设置的响应性.但是,我没有找到有关如何检查系统设置中是否启用了暗模式的任何信息.

My idea would be to override the interface style for the app in info.plist and then check the system setting and set the Interface Style for all ViewControllers according to the setting. This would make the images of the drawing normal like they should be, but keeps the responsiveness to the system setting. However, I did not find any information on how to check if the dark mode is enabled in system settings or not.

推荐答案

我不确定如何解决这个问题,但是解决方案非常简单.生成这样的图像:

I am not sure how I figured it out, but the solution is quite simple. Generating the image like this:

self.traitCollection.performAsCurrent {
    drawingImage = myCanvasView.drawing.image(from: myCanvasView.bounds, scale: CGFloat(1.0))
}

忽略系统暗模式设置,并保持图形不变.

Ignores the system dark mode setting and keeps the drawing as it is.

这篇关于在灯光模式下获取PKDrawing的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆