我尝试在应用程序启动后将视图从屏幕中心动画化到顶部:这在真实设备上看起来不错/正如预期的那样,但在模拟器上非常缓慢(这不是由于 GIF):< /p>
还有其他/更好的方法来制作动画吗?模拟器与设备之间存在这种差异的原因是什么?
示例项目如下:https://github.com/haemi/StartingAnimations
struct ContentView: View {
@State private var alignment = Alignment.center
var body: some View {
ZStack(alignment: alignment) {
Color.white
.edgesIgnoringSafeArea(.all)
Text("Hello World")
}
.edgesIgnoringSafeArea(.bottom)
.onAppear(perform: onAppearAnimations)
}
private func onAppearAnimations() {
// withAnimation(Animation.easeOut(duration: 1)) { // not sluggish
withAnimation(Animation.easeOut(duration: 1).delay(1)) { // sluggish
alignment = .top
}
}
}