我试图在UIView上创建一个闪烁的效果。当前,我正在使用使UIView无限次闪烁的代码。代码看起来像这样
到目前为止,我已经做了什么:
func startBlink() {
UIView.animate(withDuration: 0.8,//Time duration
delay:0.0,
options:[.allowUserInteraction, .curveEaseInOut, .autoreverse, .repeat],
animations: { self.alpha = 0 },
completion: nil)
}
但是此代码使ui View 闪烁了无数次。我使用了另一个代码,但仅闪烁了一次。
我想要的:
So I am pretty close but I really want to blink the UIView for finite number of times i.e 30 times, and it must stop after 30th blink.
请对此提供帮助,我想我的问题很清楚。请帮帮我。
最佳答案
使用此功能可以为“ View ”制作动画。希望对您有所帮助
extension UIView {
func flash(numberOfFlashes: Float) {
let flash = CABasicAnimation(keyPath: "opacity")
flash.duration = 0.2
flash.fromValue = 1
flash.toValue = 0.1
flash.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
flash.autoreverses = true
flash.repeatCount = numberOfFlashes
layer.add(flash, forKey: nil)
}
}
关于iOS在UIView上闪烁动画的次数有限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53171521/