问题
这里指,当将内容向上滑动时文字与状态栏重合
,而非一开始就重合
。
像这样:
解决
查阅官方指南https://developer.apple.com/design/human-interface-guidelines/ios/bars/status-bars/,给出如下建议:
总结下来,
- 使用导航栏,或
- 添加背景图,或
- 模糊状态栏。
使用导航栏
StoryBoard中选中当前Controller,选择Editor-> Embed in-> Navigation Controller。
模糊状态栏
代码实现如下:
let statusBarHeight = UIApplication.shared.statusBarFrame.height
let blur = UIBlurEffect(style: .regular)
let blurStatusBar = UIVisualEffectView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: statusBarHeight))
blurStatusBar.effect = blur
view.addSubview(blurStatusBar)
我在这里犯了一个错误:在我的代码里,这个Scene其实是一个UITableViewController,因此view就是UITableViewControllerView。如此一来,添加的模糊就会随着Table的滑动而滑动。
我最终这样解决:不使用UITableViewController,而是把UITableView放在UIViewController中。
总结
背景图和模糊状态栏虽然能起到预期效果,但是总觉得不好看。个人喜欢使用导航栏,再加上iOS11中的Prefers Large Titles效果很棒,就更喜欢了。
2018.07.14