【发布时间】:2022-12-10 09:37:03
【问题描述】:
我在 swiftui 的菜单中使用选择器进行标签可视化时遇到问题 when the selection change the text seams to be animated in writing so it appear slowly with dot ... and and after appear all the text, but I don figure out why do this 这是代码,我附上了一个简短的 gif 来演示这个问题,它出现在画布上,但也出现在模拟器和真实设备中
struct AddCostView: View {
@State private var transactionSelectionPicker: TransactionType = .outgoing
@State private var pickerPressed: Bool = false
@State private var backgroundColor: String = "Outgoing"
var body: some View {
NavigationView {
ZStack {
Color(backgroundColor)
.ignoresSafeArea(.container, edges: .top)
VStack {
HStack {
Text("Tipo di transazione:")
.font(.headline)
.foregroundColor(.secondary)
Spacer()
Menu {
Picker("transazioni", selection: $transactionSelectionPicker) {
ForEach(TransactionType.allCases, id: \.rawValue) { item in
Text(item.rawValue)
.tag(item)
}
}
.labelsHidden()
.pickerStyle(.inline)
.onChange(of: transactionSelectionPicker) { newValue in
pickerPressed.toggle()
switch newValue {
case .outgoing:
backgroundColor = "Outgoing"
case .incoming:
backgroundColor = "Incoming"
case .transfer:
backgroundColor = "Transfer"
case .currecyChange:
backgroundColor = "CurrencyChange"
}
}
} label: {
HStack(spacing: 8) {
Text(transactionSelectionPicker.rawValue)
.foregroundColor(Color(UIColor.label))
.bold()
Image(systemName: "chevron.right")
.foregroundColor(.secondary)
.rotationEffect(pickerPressed ? Angle(degrees: 90) : Angle(degrees: 0))
.font(.headline)
}
.padding()
}
.frame(width: 170, alignment: .leading)
.background(
.ultraThickMaterial, in: RoundedRectangle(cornerRadius: 8, style: .continuous)
)
.onTapGesture {
pickerPressed.toggle()
}
}
.padding()
List {
Text("t")
}
}
}
.navigationTitle("Transazione")
.navigationBarTitleDisplayMode(.inline)
}
}
}
foreach 是用枚举完成的我没有动画或事务
感谢任何能帮助我的人
【问题讨论】:
-
你知道如何解决它吗?我有同样的问题。谢谢。