【发布时间】:2019-08-09 17:54:50
【问题描述】:
我正在尝试根据切换为选择器的隐藏/显示设置动画。如果是真的或假的,我希望选择器到easeInOut。
我尝试将.animation(Animation.easeInOut(duration: 0.5)) 添加到选择器本身或选择器所在的 HStack,但两者都将动画添加到选择器内的值中,并且在滚动浏览值时应用程序崩溃。
HStack {
if showPicker {
Picker(selection: $selected.value, label: Text(selected.type)) {
ForEach(digits, id: \.self) { d in
Text("\(d)")
}
}
.frame(width: 40)
}
}
.animation(Animation.easeInOut(duration: 2))
if showPicker {
Picker(selection: $selected.value, label: Text(selected.type)) {
ForEach(digits, id: \.self) { d in
Text("\(d)")
}
}
.frame(width: 40)
.animation(Animation.easeInOut(duration: 0.5))
}
这两个选项都会动画隐藏/显示选择器,但它也会动画滚动选择器中的值,这会导致它崩溃。
任何帮助将不胜感激。
谢谢
【问题讨论】: