
我试图每隔一秒随机改变UILabel背景的颜色.我使用的代码在常规视图上工作正常,但是当我在标签上调用它时迭代速度太快.它好像持续时间的动画不会在标签上占用任何时间.知道为什么会这样吗?我实际上想要更改标签文本颜色,这就是为什么它在标签上的重要性.
colorChanges(v: lbl) // TOO FAST!colorChanges(v: someVIEw) // PERFECTcolorChanges(v: self.vIEw) // PERFECT
动画代码
func colorChanges(v: UIVIEw) { UIVIEw.animate(withDuration: 1.0,animations: { v.backgroundcolor = UIcolor(displayP3Red: CGfloat(arc4random()) / CGfloat(UInt32.max),green: CGfloat(arc4random()) / CGfloat(UInt32.max),blue: CGfloat(arc4random()) / CGfloat(UInt32.max),Alpha: 1.0) },completion: { (value: Bool) in self.colorChanges(v: v) })} 奇怪的行为
解决方法 尝试下面改变的方法:func colorChanges(v: UIVIEw) { UIVIEw.animate(withDuration: 1.0,animations: { v.layer.backgroundcolor = UIcolor(displayP3Red: CGfloat(arc4random()) / CGfloat(UInt32.max),Alpha: 1.0).cgcolor },completion: { [weak self] (value: Bool) in self?.colorChanges(v: v) }) } 请尝试更新标签textcolor动画的答案:
UIVIEw.Transition(with: v,duration: 1.0,options:.TransitionCrossdissolve,animations: { v.backgroundcolor = UIcolor(displayP3Red: CGfloat(arc4random()) / CGfloat(UInt32.max),Alpha: 1.0) if let label = v as? UILabel { label.textcolor = UIcolor(displayP3Red: CGfloat(arc4random()) / CGfloat(UInt32.max),Alpha: 1.0) } }) { [weak self] (success) in self?.colorChanges(v: v) } 总结 以上是内存溢出为你收集整理的ios – 使用UILabel表现奇怪的持续时间的动画全部内容,希望文章能够帮你解决ios – 使用UILabel表现奇怪的持续时间的动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)