こんにちはバーボタンアイテムに未定のプログレスビューを作成したいと思います。完了したら非表示にしたいのですが、hidden()メソッドにはdisabled(Bool)のようなパラメーターがありません。タスクの完了時に進行状況ビューを非表示にするにはどうすればよいですか?
パラメータがないため、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
}
}
}
そして、ビューを動的に非表示にします。
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
)
}
}
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加