一个按钮,可以渲染四种不同的播放相关模式,并在它们之间进行动画切换。
Swift Package Manager 是一个用于自动化 Swift 代码分发的工具,并且集成在 swift
编译器中。
一旦你设置好你的 Swift 包,添加 PlayButton 作为依赖项就像将其添加到你的 Package.swift
的 dependencies
值中一样简单。
dependencies: [
.package(url: "https://github.com/public-value-tech/play-button.git", .branch("main"))
]
import PlayButton
let playButton = PlayButton() // defaults to CGSize(width: 44, height: 44)
playButton.playBufferingBackgroundColor = .systemBlue
playButton.pauseStopBackgroundColor = .systemBlue
playButton.playBufferingTintColor = .white
playButon.pauseStopTintColor = .white
// Animate the mode update
playButton.setMode(.stop, animated: true)
// iOS / macCatalyst
playButton.addTarget(self, action: #selector(playButtonTapped), for: .touchUpInside))
// tvOS
playButton.addTarget(self, action: #selector(playButtonTapped), for: .primaryActionTriggered)
查看文档,或者在你将包添加到你的项目时自行编译它。
测试主要由快照测试组成。我们使用 CADisplayLink
从动画中采样一些帧,并将它们与参考快照进行比较。由于存在一些预期的偏差,我们为测试添加了一些容差。
你可能想知道这个播放按钮有什么特别之处。在这篇文章中,我们描述了在 Core Animation 中实现可中断和可逆动画时所面临的困难。