示例:rootViewController和ViewController之间的互相跳转
import UIKit
class RootViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.green
let button = UIButton(type: .custom)
button.frame = CGRect(x: 0, y: 200, width: UIScreen.main.bounds.width, height: 50)
button.backgroundColor = UIColor.white
button.setTitle("打开新的视图控制器", for: .normal)
button.setTitleColor(UIColor.gray, for: .normal)
view.addSubview(button)
button.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
}
func buttonClick() {
navigationController?.pushViewController(ViewController(), animated: true)
// 另一种跳转方式
// present(ViewController(), animated: true, completion: nil)
}
}
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.red
let button = UIButton(type: .custom)
button.frame = CGRect(x: 0, y: 200, width: UIScreen.main.bounds.width, height: 50)
button.backgroundColor = UIColor.white
button.setTitle("回到RootViewController", for: .normal)
button.setTitleColor(UIColor.gray, for: .normal)
view.addSubview(button)
button.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
}
func buttonClick() {
navigationController?.popViewController(animated: true)
// 另一种跳转方式 成对出现
dismiss(animated: true, completion: nil)
}
}
本文地址:https://blog.csdn.net/weixin_44337445/article/details/107374368
如对本文有疑问, 点击进行留言回复!!
JobScheduler 实现 特定时间,特定条件(系统空闲,电池电量,磁盘空间 ……)下执行任务
温习Android基础知识——《第一行代码(第三版)》读书笔记 Chapter 10 Service
android-GooglePlay安装来源追踪PlayInstallReferrer
网友评论