小编rit*_*lee的帖子

如何在 SwiftUI 中的三元运算符中“不执行任何操作”?

这是我的代码:

struct GameView : View {
    @State
    private var clicked1 : Bool = false
    
    var body: some View {
        HStack {
            VStack {
                Image("shape0")
                    .overlay(clicked1 ?
                        RoundedRectangle(cornerRadius:10)
                        .stroke(Color.yellow, lineWidth: 7) : pass()
                    )
                    .onTapGesure {
                        print("Image is clicked")
                    }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但周围发生了一些错误pass()

clicked1当变量为 时我不想做任何事情false

我该如何修复它?

swift swiftui

4
推荐指数
1
解决办法
1402
查看次数

标签 统计

swift ×1

swiftui ×1