问题描述
我正在使用AnimatableModifier对[[46],[11],[3],[23],[22],[33],[12]]
值进行动画处理。递增值时动画工作正常,而递减时动画不工作。
所以我有一个列表,其中有项目。所有这些项的总数在视图顶部列出。当插入一个新项目时,总数将增加,而我得到该动画。但是,在删除项目时我没有获得动画。只会降低它的值。
"basicCard": {
"title": "","subtitle": "","formattedText": "","image": {},"buttons": [
{
"title": "1-855-xxx-xxxx","openUrlAction": {
"url": "tel:+1855xxxxxxx","urlTypeHint": 0
}
},{}
]
}
}
这是我使用此修饰符的方式:
CGFloat
struct TotalExpenseAnimator: AnimatableModifier {
var pct: CGFloat = 0.0
var animatableData: CGFloat {
get { pct }
set {pct = newValue }
}
func body(content: Content) -> some View {
VStack(spacing: 0) {
content
TotalExpenseView2(pct: pct)
}
}
}
struct TotalExpenseView2: View {
let pct: CGFloat
var body: some View {
HStack(spacing: 0) {
Text(formatPrices(price: self.pct))
//.bold()
.font(Font.system(.title2))
// .padding(.top,8)
.foregroundColor(Color("TextColorWidget"))
}.onChange(of: self.pct) { (newVal) in
print(newVal) //-> val changes here so this whole thing is getting called
}
}
func formatPrices(price: CGFloat) -> String {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .currency
numberFormatter.locale = Locale.current
numberFormatter.maximumFractionDigits = 2
return numberFormatter.string(from: price as NSNumber) ?? ""
}
是一个 Text("Total Expense")
.font(Font.footnote)
.foregroundColor(Color.secondary)
.modifier(TotalExpenseAnimator(pct: ListTotalExpense(financedList: self.financedList).totalFloat))
,我将其传递给该列表,并计算所有费用并在ListTotalExpense
中获得总额
之所以调用observableObject,是因为我可以获得新值(递减值),但是根本没有动画。是因为在删除行时刷新了整个视图,导致动画被强制绕过了吗?
任何想法/建议将不胜感激!谢谢:)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)