class Testing: UIViewController {
@IBOutlet weak var slidingView: UIView!
@IBOutlet weak var sliding_label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
sliding_label.layer.cornerRadius=10
sliding_label.layer.masksToBounds = true
}
override func viewWillAppear(_ animated: Bool) {
self.sliding_label.slideInFromLeft()
// self.slidingTextLabel.slideInFromLeft(duration: 1.0, completionDelegate: self) // Use this line to specify a duration or completionDelegate
self.sliding_label.text = " "+"Sliding Registration and select location"+" "
self.sliding_label.alpha = 0
self.sliding_label.fadeIn(completion: {
(finished: Bool) -> Void in
self.sliding_label.fadeOut()
})
self.sliding_label.isHidden = false
DispatchQueue.main.asyncAfter(deadline: .now() + 7) {
self.sliding_label.fadeOut()
}
}
}
-------------------------------------------------------------------------------------------------
extensions:
extension UIView {
// Name this function in a way that makes sense to you...
// slideFromLeft, slideRight, slideLeftToRight, etc. are great alternative names
func slideInFromLeft(duration: TimeInterval = 1.0, completionDelegate: AnyObject? = nil) {
// Create a CATransition animation
let slideInFromLeftTransition = CATransition()
// Set its callback delegate to the completionDelegate that was provided (if any)
if let delegate: AnyObject = completionDelegate {
slideInFromLeftTransition.delegate = delegate as? CAAnimationDelegate
}
// Customize the animation's properties
slideInFromLeftTransition.type = kCATransitionPush
slideInFromLeftTransition.subtype = kCATransitionFromLeft
slideInFromLeftTransition.duration = duration
slideInFromLeftTransition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
slideInFromLeftTransition.fillMode = kCAFillModeRemoved
// Add the animation to the View's layer
self.layer.add(slideInFromLeftTransition, forKey: "slideInFromLeftTransition")
}
func fadeIn(duration: TimeInterval = 1.0, delay: TimeInterval = 0.0, completion: @escaping ((Bool) -> Void) = {(finished: Bool) -> Void in}) {
UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.alpha = 1.0
}, completion: completion) }
func fadeOut(duration: TimeInterval = 1.0, delay: TimeInterval = 3.0, completion: @escaping (Bool) -> Void = {(finished: Bool) -> Void in}) {
UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.alpha = 0.0
}, completion: completion)
}
}