解决方案是通过为此提供明确的可动画修改器,使高度连续可动画化。
这是工作方法。已通过Xpre 11.4 / iOS 13.4测试。
简单助手修改器的实现
struct AnimatingCellHeight: AnimatableModifier { var height: CGFloat = 0 var animatabledata: CGFloat { get { height } set { height = newValue } } func body(content: Content) -> some View { content.frame(height: height) }}使用视图修改(其他部分不变)
struct SubView: View { @State var change: Bool = false var body: some View { Rectangle() .frame(width: 200) .modifier(AnimatingCellHeight(height: change ? 300 : 200)) .foregroundColor(Color.red) .onTapGesture { withAnimation { self.change.toggle() } } }}


