[英]SwiftUI - Using drawingGroup() disables TextField
I am trying to improve the animation performance of my custom modal view.我正在尝试提高我的自定义模态视图的 animation 性能。
By using.drawingGroup(), I've managed to do so, but my TextField got disabled.通过使用.drawingGroup(),我设法做到了,但是我的TextField 被禁用了。 Like so:像这样:
And I get the error: 'Unable to render flattened version of PlatformViewRepresentableAdaptor<>'我收到错误消息:“无法呈现 PlatformViewRepresentableAdaptor<> 的扁平化版本”
Is there a way to fix this?有没有办法来解决这个问题?
Note: I am using a standard TextField.注意:我使用的是标准的 TextField。
Thanks!谢谢!
The .drawingGroup
converts entire view hierarchy into image, so you cannot use TextField
(or any other control) after this as active control, because all you see on-screen is only image. .drawingGroup
将整个视图层次结构转换为图像,因此在此之后您不能使用TextField
(或任何其他控件)作为活动控件,因为您在屏幕上看到的只是图像。
It works as documented:它按记录工作:
/// 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
The solution for this is not use .drawingGroup
for active controls, but only for UI elements w/o user interaction.对此的解决方案不是将.drawingGroup
用于活动控件,而仅用于没有用户交互的 UI 元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.