我正在尝试对自定义UIView进行动画处理,但它给了我错误:静态成员"animate"不能在类型为"Tyle"的实例上使用
这是我的班级:
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)
}
我想我在创建类时缺少一些东西,或者也许我应该使用另一个函数,但我看不到问题。
感谢您的帮助!
animate
是一个静态方法。所以应该是
UIView.animate(withDuration: 0.5, delay: 0.3, options: [.repeat, .curveEaseOut, .autoreverse], animations: {
}, completion: nil)