【问题标题】:SwiftUI - Using drawingGroup() disables TextFieldSwiftUI - 使用 drawingGroup() 禁用 TextField
【发布时间】:2020-06-04 05:48:15
【问题描述】:

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

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

我收到错误消息:'无法呈现 PlatformViewRepresentableAdaptor 的扁平化版本'

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

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

谢谢!

【问题讨论】:

    标签: ios swift swiftui metal


    【解决方案1】:

    .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 元素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-01
      • 2021-06-16
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多