SwiftUI - 使用 drawingGroup() 禁用 TextField

Mof*_*waw 1 ios swift metal swiftui

我正在尝试提高自定义模态视图的动画性能。

通过使用 .drawingGroup(),我设法做到了,但是我的 TextField 被禁用了。像这样:

在此处输入图片说明

我收到错误消息:“无法呈现 PlatformViewRepresentableAdaptor<> 的扁平版本”

有没有办法来解决这个问题?

注意:我使用的是标准 TextField。

谢谢!

Asp*_*eri 6

.drawingGroup转换整个视图层次为图像,所以您不能使用TextField后此为主动控制(或任何其他控件),因为你在屏幕上看到的只是图像。

它的工作原理如下:

/// Composites this view's contents into an offscreen image before final
/// display.
///
/// Views backed by native platform views don't render into the image.
/// Instead, they log a warning and display a placeholder image to highlight
/// the error.
///
/// - Parameters:
///   - opaque: A Boolean value that indicates whether the image is opaque.
///     If `true`, the alpha channel of the image must be one.
///   - colorMode: The working color space and storage format of the image.
/// - Returns: A view that composites this view's contents into an offscreen
///   image before display.
public func drawingGroup(opaque: Bool = false, colorMode: ColorRenderingMode = .nonLinear) -> some View
Run Code Online (Sandbox Code Playgroud)

对此的解决方案不适.drawingGroup用于活动控件,而仅适用于没有用户交互的 UI 元素。