原文链接:https://github.com/fzhlee/SwiftUI-Guide#-%E7%AC%AC4%E8%8A%82rotationeffectspring-
本节课演示旋转动画的制作,并且旋转动画以spring弹性样式的时间曲线进行
示例代码:
struct ContentView : View {
@State var angle: Double = 0 //图像视图的旋转角度
var body: some View {
VStack{
Image("logo")
.rotationEffect(Angle.init(degrees: angle)) //按照属性的大小,将图像视图旋转指定的角度
.animation(.spring()) //设置动画的时间曲线为spring弹性样式,也就是说在指定角度的旋转动画的末尾,动画会快速反复的执行数次,具有类似于弹簧的效果
Divider().fixedSize()
Button(action: {
self.angle += 90 //当按钮被点击时,将角度属性的值加上90
}) {
Text("Rotation Effect")
}
}
}
}
![](https://img.haomeiwen.com/i2466108/39d318d1448dae52.gif)
网友评论