我有一个UIView,我希望在10秒内将不透明度设置为0。但是,动画应该在7.5秒后开始。这是因为我首先动画帧变换,UIView应该只淡出动画的最后1/4持续时间。这是我的尝试:
override func viewDidLoad() {
let x = UIView()
view.addSubview(x)
x.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
x.backgroundColor = .black
let animation = CABasicAnimation(keyPath: "opacity")
animation.timingFunction = CAMediaTimingFunction(controlPoints: 0, 0, 0, 1)
animation.fromValue = 1
animation.toValue = 0
animation.duration = 10
animation.fillMode = kCAFillModeForwards
x.layer.add(animation, forKey: "opacity")
}
UIView瞬间淡出。如何使用mediaTimingFunction延迟它?
答案 0 :(得分:0)
将持续时间设置为2.5秒,并在开始帧动画后7.5秒开始动画
animation.beginTime = CACurrentMediaTime() + 7.5