This is one approach you can follow to achieve this:
Take 2 Container UIView
and 2 line view (you may take UIView
again) and 2 UIImageView
(or any for green view). So your StoryBoard
should look like this :

Make sure your container views are clips to bound
(you can set it from storyboard only).
Now you can achieve the animation easily by CGAffineTransform
.
I will call outlet names for animated view as imageViewOne
and imageViewTwo
.
In viewDidLoad()
write this (if initially views are hidden):
imageViewOne.transform = CGAffineTransform(translationX: 0.0, y: containerViewOne.bounds.height)
imageViewTwo.transform = CGAffineTransform(translationX: 0.0, y: -containerViewOne.bounds.height)
Then to show it with animation:
//To build out of line
UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.5, options: .curveEaseInOut, animations: {
self.imageViewOne.transform = .identity
self.imageViewTwo.transform = .identity
}, completion: nil)
//To build into line
UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.5, options: .curveEaseInOut, animations: {
self.imageViewOne.transform = CGAffineTransform(translationX: 0.0, y: containerViewOne.bounds.height)
self.imageViewTwo.transform = CGAffineTransform(translationX: 0.0, y: -containerViewOne.bounds.height)
}, completion: nil)