gpt4 book ai didi

Swiftui 进度 View 隐藏

转载 作者:行者123 更新时间:2023-12-04 16:38:49 29 4
gpt4 key购买 nike

您好,我想在栏按钮项上制作未确定的进度 View 。完成后我想让它隐藏,但 hidden() 方法没有像 disabled(Bool) 这样的参数。任务完成后如何隐藏进度 View ?
这就是我要的
enter image description here
我不知道如何在 swiftui 上以编程方式隐藏它,因为它没有参数。
这是代码

.navigationBarItems(leading:
Button(action: {
self.presentationMode.wrappedValue.dismiss()
}, label: {
Text("Cancel")
.foregroundColor(.orange)
})
, trailing:
//this should be hidden when the work done not always
ProgressView()
.hidden()
)

最佳答案

您可以创建该 ViewExtension

extension View {
@ViewBuilder func isHidden(_ isHidden: Bool) -> some View {
if isHidden {
self.hidden()
} else {
self
}
}
}
然后动态隐藏 View :
struct ContentView : View {

@State var isHidden = false

var body : some View {

NavigationView {
VStack {
Text("Hello World")

Button(action: {
self.isHidden.toggle()
})
{
Text("Change loading")
}
}
.navigationBarItems(leading:
Button(action: {
}, label: {
Text("Cancel")
.foregroundColor(.orange)
})
, trailing:
ProgressView()
.isHidden(isHidden) //<< isHidden takes a bool whether it should be hidden
)
}
}
}

关于Swiftui 进度 View 隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64878620/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com