如何將其轉換爲Swift 3?我試過,但我不斷收到動畫.fromValue和animation.toValue錯誤(這是隻有2條線,我需要)轉換爲Swift 3
extension UIView {
func shake() {
let animation = CABasicAnimation(keyPath: "position")
animation.duration = 0.07
animation.repeatCount = 3
animation.autoreverses = true
// This line produces error
animation.fromValue = NSValue(CGPoint: CGPointMake(self.center.x - 10, self.center.y))
// And this line produces error
animation.toValue = NSValue(CGPoint: CGPointMake(self.center.x + 10, self.center.y))
self.layer.addAnimation(animation, forKey: "position")
}
}
什麼是錯誤? –