[iOS开发]滑动时状态栏和内容重合

问题

这里指,当将内容向上滑动时文字与状态栏重合而非一开始就重合
像这样:
问题

解决

查阅官方指南https://developer.apple.com/design/human-interface-guidelines/ios/bars/status-bars/,给出如下建议:
网页截图
总结下来,

  1. 使用导航栏,或
  2. 添加背景图,或
  3. 模糊状态栏。

使用导航栏

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

猜你喜欢

转载自blog.csdn.net/twllx/article/details/81046565