Hi I am developing one application.In that i did the animation for one view to move from left to right and right to left and changing the values for labels contained in that
Using Swift 4.2 and Swift 5
Animate UIView from left to right or vice versa. 0 for Left to right and 1 for Right to left
class AnimationView: UIView {
enum Direction: Int {
case FromLeft = 0
case FromRight = 1
}
@IBInspectable var direction : Int = 0
@IBInspectable var delay :Double = 0.0
@IBInspectable var duration :Double = 0.0
override func layoutSubviews() {
initialSetup()
UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.2, options: .curveEaseIn, animations: {
if let superview = self.superview {
if self.direction == Direction.FromLeft.rawValue {
self.center.x += superview.bounds.width
} else {
self.center.x -= superview.bounds.width
}
}
})
}
func initialSetup() {
if let superview = self.superview {
if direction == Direction.FromLeft.rawValue {
self.center.x -= superview.bounds.width
} else {
self.center.x += superview.bounds.width
}
}
}
}