最佳答案
如果你想用动画不断改变 View 的背景颜色,你可以这样设置。
var colors: [UIColor] = [.red, .blue, .green]
func startAnimation(index: Int) {
UIView.animate(withDuration: 2.5, delay: 0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
self.view.backgroundColor = self.colors[index]
}) { (finished) in
var currentIndex = index + 1
if currentIndex == self.colors.count { currentIndex = 0 }
self.startAnimation(index: currentIndex)
}
}
并使用索引 0
调用此函数。
self.startAnimation(index: 0)
关于ios - 像 Instagram 登录一样更改渐变背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40229702/