状态栏下的CollectionView标头内容 [英] CollectionView header content under status bar

查看:67
本文介绍了状态栏下的CollectionView标头内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是一个启用了安全区域布局指南的,仅限于视图的顶部,左侧,右侧和底部的集合视图:

Here's a collection view constrained to top, left, right, and bottom of the superview with safe area layout guide enabled:

我希望我的收藏集视图标题显示在状态栏下 下.对于iPhone 4-8+的屏幕尺寸,我已经实现了这一点,方法是取消选中控制器主view的大小检查器中的安全区域布局指南,并添加以下代码:

I want my collection view header to be shown under the status bar. I've achieved this for iPhone 4 - 8+ screen dimensions by unchecking Safe Area Layout Guide in the size inspector for the controller's main view, and adding the following code:

collectionView.contentInset = UIEdgeInsets(top: -20, left: 0, bottom: 0, right: 0)

这对于非iPhone X 的查看尺寸看起来很棒:

This looks great for non iPhone X view sizes:

但是,对于iPhone X,这将导致以下输出:

However, for the iPhone X, this leads to the following output:

iPhone X在状态栏上有其自己的尺寸.进一步调整顶部插图可以,但是会抵消其他设备的尺寸.我想知道是否有一种更优雅的方式来实现此行为.

The iPhone X has its own dimensions for the status bar. Adjusting the top inset further does work, but will over-offset the other device sizes. I am wondering if there's an more elegant way to achieve this behaviour.

推荐答案

找到了解决方案:

collectionView.contentInset.top = -UIApplication.shared.statusBarFrame.height

这篇关于状态栏下的CollectionView标头内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆