繁体   English   中英

SwiftUI - 使用 drawingGroup() 禁用 TextField

[英]SwiftUI - Using drawingGroup() disables TextField

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

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

在此处输入图像描述

我收到错误消息:“无法呈现 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 元素。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM