需求描述
登陆页要求背景图全屏展示,网上查了很多,发现没有找到适合的,问了组里的大佬,大佬随便提了一句隐藏navigationbar就行了,汗颜。
实现方法
在 VC 中设置背景图
self.view.layer.contents = UIImage(named: "launch_screen_background")?.cgImage
将navigationbar隐藏
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// 隐藏顶部导航
navigationController?.navigationBar.isHidden = true
}
此时导航栏上的返回按钮已经不见了,手动添加返回按钮
这里使用了 rxswift 库进行布局和事件的的绑定
// 在 viewdidload 函数中实现
var backBtn = UIButton()
backBtn.setImage(UIImage(named: "back_btn_dark"), for: .normal)
view.addSubview(backBtn)
backBtn.snp.makeConstraints { make in
make.left.equalToSuperview().offset(12.pxl)
make.top.equalToSuperview().offset(33.px)
make.width.height.equalTo(24.px)
}
// 返回按钮的事件绑定
backBtn.rx.tap.subscribe { [weak self] _ in
self?.navigationController?.popViewController(animated: true)
}.disposed(by: disposeBag)