代码语言:javascript复制
class subViewController: UIViewController {
//nib文件的初始化
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
print(#function)
}
//storyboard文件的初始化
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//只有UIView且xib时才会调用该方法
override class func awakeFromNib() {
super.awakeFromNib()
print(#function)
}
//加载vc中的view。可以返回自定义view
override func loadView() {
super.loadView()
// view = UIView()
print(#function)
}
//vc加载完成后
override func viewDidLoad() {
super.viewDidLoad()
print(#function)
// view = UIView()
view.backgroundColor = UIColor.red
// Do any additional setup after loading the view.
}
//vc即将出现
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print(#function)
}
//根视图的布局边距已更改。
override func viewLayoutMarginsDidChange() {
print(#function)
}
//根视图的布局安全边距已更改。>ios11.0
override func viewSafeAreaInsetsDidChange() {
print(#function)
}
//当前视图更新约束是调用.>ios11.0
override func updateViewConstraints() {
super.updateViewConstraints()
print(#function)
}
//布局更新时代用
//layoutIfNeeded调用更新后会也会调用
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
print(#function)
}
//布局更新完成
//layoutIfNeeded调用更新后会也会调用
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
print(#function)
}
//页面已经出现
override func viewDidAppear(_ animated: Bool) {
print(#function)
}
//页面即将消失
override func viewWillDisappear(_ animated: Bool) {
print(#function)
}
//页面已经消失
override func viewDidDisappear(_ animated: Bool) {
print(#function)
}
//内存警告时调用
override func didReceiveMemoryWarning() {
}
//vc回收时调用
deinit {
print(#function)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
view.setNeedsLayout()
view.layoutIfNeeded()
}
}