轻松观察 SwiftUI 动画进度
动画观察者
轻松观察 SwiftUI 动画进度!🔬
设置
将以下内容添加到Package.swift
:
.package(url: "https://github.com/stateman92/AnimationObserver", exact: .init(0, 0, 1))
用法
public struct CustomView {
@Binding private var playing: Bool
@State private var progress: Double
public init(playing: Binding<Bool>) {
self._playing = playing
self.progress = playing.wrappedValue ? .zero : 1
}
public var body: some View {
// ...
.animationObserver(for: progress) {
playing = true
} onComplete: {
playing = false
}
}
}
有关详细信息,请参阅示例应用程序。