移动视图动画在模拟器上看起来非常缓慢,但在设备上很好

时间:2021-05-07 08:53:22

标签: swiftui

我尝试在应用程序启动后将视图从屏幕中心动画化到顶部:这在真实设备上看起来不错/正如预期的那样,但在模拟器上非常缓慢(这不是由于 GIF):< /p>

enter image description here

还有其他/更好的方法来制作动画吗?模拟器与设备之间存在这种差异的原因是什么?

示例项目如下: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
        }
    }
}

0 个答案:

没有答案