【发布时间】:2017-12-27 07:55:22
【问题描述】:
我在 Xcode 中有一个单视图应用程序,并在 ViewController.swift 中执行以下操作。我的目标是让屏幕在 5 秒内逐渐填满棕色矩形。我错过了什么还是方法完全错误?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let expandAnimation: CABasicAnimation = CABasicAnimation(keyPath: "path")
expandAnimation.fromValue = UIBezierPath(rect: CGRect(x: 0.0, y: 0.0, width: 0.0, height: 0.0))
expandAnimation.toValue = UIBezierPath(rect: CGRect(x: 0.0, y: 0.0, width: self.view.bounds.size.width, height: self.view.bounds.size.height))
expandAnimation.duration = 5.0
expandAnimation.fillMode = kCAFillModeForwards
expandAnimation.isRemovedOnCompletion = false
let rectLayer: CAShapeLayer = CAShapeLayer()
rectLayer.fillColor = UIColor.brown.cgColor
rectLayer.path = UIBezierPath(rect: CGRect(x: 0.0, y: 0.0, width: 0.0, height: 0.0)).cgPath
rectLayer.add(expandAnimation, forKey: nil)
self.view.layer.addSublayer(rectLayer)
}
我不希望颜色逐渐出现。我想要一种玻璃填充的效果。想象一下这个
除了花哨的波浪效果。
【问题讨论】:
-
您想让您的视图逐渐将其颜色从一种颜色更改为另一种颜色?
-
从空到完全充满棕色
-
我需要这种波浪效果的注水,请指导。
标签: ios uiviewcontroller swift4 uibezierpath cabasicanimation