我有这个扩展名,我正在使用它作为一个闪光效果。它消失了,只有一次。
如何在用户输入之前重复此操作? IBAction低于扩展名。
extension UIView {
func fadeIn(duration: NSTimeInterval = 1.0, delay: NSTimeInterval = 0.0, completion: ((Bool) -> Void) = {(finished: Bool) -> Void in}) {
UIView.animateWithDuration(duration, delay: delay, options: UIViewAnimationOptions.CurveEaseIn, animations: {
self.alpha = 1.0
}, completion: completion) }
func fadeOut(duration: NSTimeInterval = 1.0, delay: NSTimeInterval = 0.0, completion: (Bool) -> Void = {(finished: Bool) -> Void in}) {
UIView.animateWithDuration(duration, delay: delay, options: UIViewAnimationOptions.CurveEaseIn, animations: {
self.alpha = 0.0
}, completion: completion)
}
}
单独IBAction
@IBAction func SendAge(sender: AnyObject) {
let newAge = String(inputField.text!)
if ((inputField.text?.isEmpty) != false) {
self.sentence.blink()
self.sentence.text = "Enter a number!"
self.sentence.textColor = UIColor.redColor()
}
else {
sentence.text = "Oh, you're \(newAge)"
return()
}
}
答案 0 :(得分:2)
这是一种非常简单的方法:
extension UIView {
func blink(duration: NSTimeInterval = 1.0) {
self.alpha = 1
UIView.animateWithDuration(duration, delay: 0,
options: [.CurveEaseIn, .Autoreverse, .Repeat], animations: {
self.alpha = 0
}, completion: nil)
}
}
要取消它,只需将视图的alpha
设置为1。
答案 1 :(得分:0)
您应该使用NSTimer
scheduledTimerWithTimeInterval(interval: NSTimeInterval, target:, selector, userInfo:, repeats: bool)
上可以设置为true的方法,只要计时器正在运行,这个方法就会运行。