You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SwiftUI中无参数Animation案例的TimeInterval时长是多少?

SwiftUI无参数动画的默认时长

SwiftUI中无需传入duration参数的动画(.default、.linear、.easeIn、.easeOut、.easeInOut),默认时间间隔均为0.35秒。

你可以通过以下代码验证该数值:

struct AnimationDurationTest: View {
    @State private var isAnimating = false
    private var startTime: Date?
    
    var body: some View {
        Rectangle()
            .frame(width: isAnimating ? 300 : 100, height: 100)
            .onAppear {
                startTime = Date()
                withAnimation {
                    isAnimating = true
                }
            }
            .onChange(of: isAnimating) { _ in
                if let start = startTime {
                    let duration = Date().timeIntervalSince(start)
                    print("动画时长:\(duration)") // 输出结果接近0.35
                }
            }
    }
}

该时长是苹果框架内置的默认值,虽未在官方文档中明确标注,但实际测试可确认所有此类无参数动画的默认时长一致。

内容的提问来源于stack exchange,提问作者Sam Doggett

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 14:05:33