在swift静态错误中自定义UIViewanimation

我想animation自定义的UIView,但它给了我错误:静态成员'animation'不能用于types'Tyle'的实例,

这是我的class级:

class Tile: UIView { var actualPosition:Position = Position(dimX: 0,dimY: 0) var correctPosition:Position = Position(dimX: 0,dimY: 0) var imageView: UIImageView = UIImageView() override init(frame: CGRect) { super.init(frame: frame) addSubview(imageView) imageView.translatesAutoresizingMaskIntoConstraints = false } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } } 

而这个我正在使用的代码:

 for i in 0...self.tilesMovedIndex.count - 1 { let view = self.gameTiles[self.tilesMovedIndex[i]] view.animate(withDuration: 0.5, delay: 0.3, options: [.repeat, .curveEaseOut, .autoreverse], animations: { }, completion: nil) } 

我想我在创build类时错过了一些东西,或者我应该使用另一个函数,但是我看不到这个问题。

谢谢您的帮助!

animate是一个静态的方法。 所以应该是

 UIView.animate(withDuration: 0.5, delay: 0.3, options: [.repeat, .curveEaseOut, .autoreverse], animations: { }, completion: nil)