当 NetStatus 发生变化时,我尝试制作流畅的动画,但它并没有像我想要的那样工作。
我想获得与按下带有切换动画的按钮时相同的效果。注释按钮动画效果很好,我尝试通过缩放文本框架的高度来复制它。
注释按钮代码仅用于我想要的动画效果的工作示例(优雅地展开和关闭),我不需要此代码。
我怎样才能做到这一点?
import SwiftUI
struct NoNetwork: View {
let screenSize: CGRect = UIScreen.main.bounds
@ObservedObject var online = NetStatus()
var body: some View {
VStack{
Text("NoNetworkTitle")
.fontWeight(.bold)
.foregroundColor(Color.white)
.frame(width: screenSize.width, height: self.online.connected ? 0 : 40, alignment: .center)
// .animation(.easeIn(duration: 5))
.background(Color.red)
// Button(action: {
// withAnimation {
// self.online.connected.toggle()
// }
// }, label: {
// Text("Animate")
// })
}
}
}
struct NoNetwork_Previews: PreviewProvider {
static var previews: some View {
NoNetwork()
}
}