SwiftUI中的动画绑定

时间:2020-09-11 12:00:36

标签: swift animation binding swiftui

我有以下代码,根据import numpy as np import pandas as pd import xlrd from pandas import Series, DataFrame df = pd.read_excel ('C:/Data.xlsx', sheet_name = 'Sheet1', usecols = ['PaymentType', 'Money', 'Date']) df['Date'] = pd.to_datetime(df['Date']) df = df.pivot_table(index = ['Date'], columns = ['PaymentType']).fillna(0) df = pd.merge_asof(df['Money', 'fee'], df['Money', 'rentPay'], on = 'Date', tolerance = pd.Timedelta('2s')) #df.to_excel("Finale123.xlsx") print(df) 部分显示或隐藏Test视图。我可以将Binding<Bool>调用包装在testVisible.toggle()中,但是,理想情况下,我想确保withAnimation绑定始终保持动画状态,即使在没有visible的情况下也是如此。我该如何确保只要更改withAnimation绑定,该更改就会生效?

visible

1 个答案:

答案 0 :(得分:1)

.animation()视图中添加Text修饰符:

struct Test: View {
    @Binding var visible: Bool
    
    var body: some View {
        Text("Test")
            .opacity(visible ? 0.5 : 0)
            .animation(.linear(duration: 0.5))
    }
}