【问题标题】:UIViewRepresentable view disappears when contextMenu is activated激活 contextMenu 时 UIViewRepresentable 视图消失
【发布时间】:2021-11-18 03:05:00
【问题描述】:

我正在尝试将上下文菜单与 UIViewRepresentable 一起使用。 当上下文菜单被激活时,UIViewRepresentable 消失。

代码如下:

UIView 可表示的视图:

struct TestView: UIViewRepresentable {
    func makeUIView(context: Context) -> some UIView {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
        view.backgroundColor = UIColor.red
        return view
    }
    func updateUIView(_ uiView: UIViewType, context: Context) {
        //
    }
}

内容视图:

struct ContentView: View {
    var body: some View {
        TestView()
            .frame(width: 200, height: 200)
            .contextMenu {
                Text("Context Menu")
            }
    }
}

如何让 UIViewRepresentable 不消失?

【问题讨论】:

    标签: swiftui contextmenu uiviewrepresentable


    【解决方案1】:

    我最近使用返回自定义UIImageViewUIViewRepresentable 视图遇到了这个确切的问题。修复是使用上下文菜单向视图添加clipped() 修饰符。不确定这是否适用于您的案例,因为我的案例涉及图像。

    这是在运行 iOS 15.1 的 iPhone 12 Pro 上测试的。

    【讨论】:

      猜你喜欢
      • 2021-06-27
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2012-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多