Swift 3 & 4 Please Add necessary objects like tableView
import UIKit class SecondViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { @IBOutlet var tabl: UITableView! var name = ["tony","abu"] override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return name.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = UITableViewCell() cell.textLabel?.text = name[indexPath.row] return cell } override func viewWillAppear(_ animated: Bool) { tabl.center.x = self.view.frame.width/5 UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity:0.45, options: [], animations: ({ self.tabl.center.x = self.view.frame.width/3 //self.buttonAction.center.x = self.view.frame.width/2 }), completion: nil) } }
UIView's animate methods. They work the same way in Swift as they did in Obj-C.CABasicAnimationorCAKeyframeAnimation, where you set the x/y position or the opacity via the animation. See documentation or other questions showing how to do it in Objective-C, there is plenty of it. If you get stuck, update this question with what you tried to do and a description of what isn't working.