Animating custom UIView in swift static error

2019-03-03 18:31发布

I'm trying to animate a custom UIView but it gives me the error: Static member 'animate' cannot be used on instance of type 'Tyle'

This is my 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")
}
}

And this the code I'm using:

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)
    }

I suppose I'm missing something when creating the class or maybe I should use another function but I can't see the problem.

Thanks for the help!

1条回答
Anthone
2楼-- · 2019-03-03 18:52

animate is a static method. So it should be

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

    }, completion: nil)
查看更多
登录 后发表回答