【发布时间】:2016-12-29 18:14:26
【问题描述】:
我正在关注this 教程。代码 sn-p 可以在here 找到。在某些动画中,动画直接发送到UIView。就像下面的代码 sn-p。
问题1:这个UIView是什么类的什么属性?还是我们正在向屏幕上所有内容的 UIView 发送消息,执行代码块中的内容?我只是想了解我们在此处发送的消息是哪个属性...
protocol Flashable {}
extension Flashable where Self: UIView {
func flash() {
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseIn, animations: {
self.alpha = 1.0
}) { (animationComplete) in
if animationComplete == true {
UIView.animate(withDuration: 0.3, delay: 2.0, options: .curveEaseOut, animations: {
self.alpha = 0.0
}, completion: nil)
}
}
}
}
^^^我没有得到UIView.animate 部分。 ^^^
对于某些人来说,它不会直接发送给UIView。
extension Jitterable where Self: UIView {
func jitter() {
let animation = CABasicAnimation(keyPath: "position")
animation.duration = 0.05
animation.repeatCount = 5
animation.autoreverses = true
animation.fromValue = NSValue(cgPoint: CGPoint.init(x: self.center.x - 5.0, y: self.center.y))
animation.toValue = NSValue(cgPoint: CGPoint.init(x: self.center.x + 5.0, y: self.center.y))
layer.add(animation, forKey: "position")
}
}
^^^上面的代码比较好理解^^^
但是,当您想同时调用它们时:
errorLabel.flash()
errorLabel.jitter()
问题2:两种动画的编写方式有什么区别?
【问题讨论】:
标签: ios swift animation uiview