SwiftUI 动画
2020-07-12 本文已影响0人
ShenYj
- 在
SwiftUI
中, 你可以将任意的改变过程封装进一个withAnimation
块中. 默认,SwiftUI
会对这种改变采用fade in/out
的方式进行动画.
效果:
animation.gif实例代码:
import SwiftUI
struct AnimationView: View {
@State private var showDetail = false
var body: some View {
Button(action: {
withAnimation {
self.showDetail = !self.showDetail
}
}) {
Image(systemName: "chevron.right.circle")
.imageScale(.large)
.rotationEffect(.degrees(showDetail ? 90 : 0))
.scaleEffect(showDetail ? 1.5 : 1)
.padding()
}
}
}
struct AnimationView_Previews: PreviewProvider {
static var previews: some View {
AnimationView()
}
}
替换SceneDelegate
的根视图
let contentView = AnimationView()