SwiftUI - 使用 drawingGroup() 禁用 TextField

SwiftUI - Using drawingGroup() disables TextField

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

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

我收到错误:'Unable to render flattened version of PlatformViewRepresentableAdaptor<>'

有办法解决这个问题吗?

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

谢谢!

.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

此问题的解决方案不是将 .drawingGroup 用于活动控件,而是仅将 UI 元素用于 w/o 用户交互。