I want to have a line in the center of the screen and animate it like a snake
This is step by step animation I want to make
How can I do this?
One method is using a UIView with the background color. Try something like this.
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
let redLine = UIView()
redline.backgroundColor = UIColor.red
redLine.frame = GCRect(x: screenWidth / 2, y: screenHeight / 2, width: 0, height: 0)
UIView.animate(withDuration: 2, animations: {
redLine.frame = GCRect(x: screenWidth / 2, y: screenHeight / 2, width: 0, height: (screenHeight / 2) - 4)
}) { finished in
redLine.frame = GCRect(x: screenWidth / 2, y: (screenHeight / 2) - 4, width: 0, height: 1)
}
With this, you can achieve any amount of red line movement.
The other method is to actually draw a line. I won't go into detail about that, but would recommend this article.
One last thing... On stack overflow we appreciate people who show they properly researched a topic before just asking a question. Using google, I was able to quickly come up with many tutorials on how to do what you are looking for. Try to do research yourself, because often a tutorial will have far more detail that is important than a stack overflow answer.