iOS - 渐变之间的过渡?
Posted
技术标签:
【中文标题】iOS - 渐变之间的过渡?【英文标题】:iOS - Transition between gradients? 【发布时间】:2019-06-24 17:58:34 【问题描述】:我正在尝试在两个不同的渐变之间无休止地旋转背景颜色,但实际过渡的持续时间没有预期的那么长(持续时间不到一秒,并且每次过渡之间没有延迟)。
var backgroundColours = [CAGradientLayer()]
var backgroundLoop = 0
override func viewDidLoad()
super.viewDidLoad()
backgroundColours = [Colors.init().one, Colors.init().two] // These are two CAGradientLayers but I haven't included their code
backgroundLoop = 0
self.animateBackgroundColour()
func animateBackgroundColour ()
backgroundLoop = (backgroundLoop + 1) % (backgroundColours.count)
UIView.animate(withDuration: 2.0, delay: 2.0, options: .curveLinear, animations:
self.view.backgroundColor = UIColor.clear
let backgroundLayer = self.backgroundColours[self.backgroundLoop]
backgroundLayer.frame = self.view.frame
self.view.layer.insertSublayer(backgroundLayer, at: 0)
, completion: (Bool) -> Void in
self.animateBackgroundColour()
)
这些都在ViewController
类里面
【问题讨论】:
【参考方案1】:UIView.animate
仅对大约五个专门的 view 属性进行动画处理。您没有为任何这些属性设置动画。你想要的是 layer 动画(例如 CABasicAnimation)。
【讨论】:
以上是关于iOS - 渐变之间的过渡?的主要内容,如果未能解决你的问题,请参考以下文章