首页 > 解决方案 > 移动视图动画在模拟器上看起来超级迟钝,但在设备上很好

问题描述

我尝试在应用程序启动后将视图从屏幕中心动画到顶部:这在真实设备上看起来很好/符合预期,但在模拟器上超级慢(这不是由于 GIF):

在此处输入图像描述

有没有另一种/更好的方法来做那个动画?这种差异模拟器与设备的原因是什么?

这是示例项目: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
        }
    }
}

标签: swiftui

解决方案


推荐阅读