如何将其转换为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")
}
}
什么是错误? –