[英]Move inside list element position in SwiftUI
當我單擊另一個列表元素時,我正在嘗試移動列表元素 position
當我點擊那會發生什么
我需要視圖向上移動並保持這種狀態,而無需用戶移動它
VStack{
VStack{
Button(action: {
self.iconeView.toggle()
}) {
ZStack{
self.icone.renderingMode(.original)
.frame(width: UIScreen.main.bounds.width * 0.4, height: UIScreen.main.bounds.height * 0.2)
}
}
}//Photo
.padding(.bottom, 54)
.padding(.top, 42)
List {
VStack(alignment: .leading){
Text("Nome do remédio")
}//Medicine Name
.padding(.bottom, 10)
VStack(alignment: .leading){
Text("Quantidade de remédio")
}// Quantity
.padding(.bottom, 50)
VStack(alignment: .leading){
Text("Horario Inicial")
}//Start time
}//List
}//Screen
由於您已經預定義了元素數量,因此在這里使用ScrollView
而不是List
更合適。 所以解決方案可以如下(在偽代碼中)
更新完整的演示代碼。 使用 Xcode 11.4 / iOS 13.4 測試
struct DemoMoveToTopView: View {
@State private var showMedicalName = true
@State private var showQuantaty = true
var body: some View {
ScrollView {
VStack {
if self.showMedicalName {
VStack(alignment: .leading){
Text("Nome do remédio")
}//Medicine Name
.frame(width: 300, height: 100)
.border(Color.red).background(Color.yellow)
.padding(.bottom, 10)
.transition(.opacity)
}
if self.showQuantaty {
VStack(alignment: .leading){
Text("Quantidade de remédio")
}// Quantity
.frame(width: 300, height: 100)
.border(Color.red).background(Color.yellow)
.padding(.bottom, 50)
.transition(.opacity)
}
VStack(alignment: .leading){
Text("Horario Inicial")
}//Start time
.frame(width: 300, height: 100)
.border(Color.red).background(Color.white)
.onTapGesture {
self.showMedicalName.toggle() // << hide/show above
self.showQuantaty.toggle() // << hide/show above
// .. do other needed
}
}.animation(.default)
}//ScrollView
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.