Swift 3 hãy Thêm các đối tượng cần thiết như 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)
}
}
Nguồn
2017-12-04 05:59:33
cách tương tự như trong Objective C. – Kevin
tôi không thể tìm thấy bất cứ điều gì với các loại hình hoạt hình mà tôi muốn. Tôi chỉ muốn có một slide đơn giản hoặc mờ dần. Không phải là một trò chơi OpenGL. – Benr783
Tra cứu các phương thức animate của 'UIView'. Họ làm việc theo cách tương tự trong Swift như họ đã làm trong Obj-C. –