ios - CollectionView 项目隐藏在顶栏后面
问题描述
我有一个消息传递应用程序,问题是第一条消息不可见,当我拖动集合视图以查看顶部消息时,我可以看到它们,但是当我松开手指时,集合视图跳回来,隐藏了前 5 条消息位于屏幕顶部
正如我们从图像中看到的那样,有一条消息(实际上顶部有 5 条消息),但是我必须拖动集合视图才能查看这些消息。我认为集合视图的大小实际上比屏幕大,但是两者的collectionView.frame.height
高度UIScreen.main.bounds.height
相同,可以吗?. 这是我用来设置集合视图的代码:
/// Function that configures the ChatViewController collection view
private func configureCollectionView() {
collectionView?.backgroundColor = Theme.current.chatGeneralBackground
collectionView?.alwaysBounceVertical = true
collectionView?.keyboardDismissMode = .onDrag
// Register the chat cell and the loading cellx`
collectionView?.register(ChatCell.self, forCellWithReuseIdentifier: chatCellIdentifier)
collectionView?.register(LoadingCollectionViewCell.self, forCellWithReuseIdentifier: loadingCellIdentifier)
// Initialize the original height of the collection view
collectionViewOriginalHeight = collectionView.frame.height
}
我究竟做错了什么?
解决方案
从 iOS 7.0 开始,所有视图都自动位于导航栏、工具栏和标签栏后面,以提供 Apple 所谓的“上下文”。
例如,如果您不希望视图控制器位于任何栏后面,请在viewWillAppear
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
self.edgesForExtendedLayout = []
}
推荐阅读
- c# - Bot Framework - 如何访问部分类中定义的实体
- mongodb - 在 mongodb 中加入多个集合并保留所有字段
- google-apps-script - 谷歌表格我正在编写一个宏并试图跳过几行代码
- python - Mysql LOAD DATA INFILE - 越来越慢
- nginx - 在单个服务器块中为不同网站添加多个 NGINX 反向代理
- javascript - 是否有必要在按钮单击时清除超时反应?
- arrays - 在 txt 文件中使用 fscanf 并将值保存到表中
- r - 根据R中的每一行统计一定时间范围内的行数(tidyverse)
- java - 如何避免在@XmlType propOrder 中添加所有字段并从父类导入字段
- php - 通过作曲家下载 laravel/nexmo 时出错