ios - 子视图的底部锚点相对于父视图的顶部锚点,而不是预期的底部锚点
问题描述
我有一个 UICollectionView,在每个 UICollectionViewCell 中我都有一个应该位于单元格底部的 UILabel。除了将 UILabel 相对于单元格底部定位的约束(假设标签在单元格底部上方 40 点)之外,所有约束都正常工作。相反,我的代码将其放置在单元格顶部下方40 点处,因此 UILabel 位于单元格顶部,而不是底部。代码清楚地为单元格的 contentView 指定了底部锚点,所以我不确定发生了什么。
// Constraints work correctly
self.text.widthAnchor.constraint(equalToConstant: CellConstants.textWidthAnchor).isActive = true
self.text.heightAnchor.constraint(equalToConstant: CellConstants.textHeightAnchor).isActive = true
self.text.leftAnchor.constraint(equalTo: self.contentView.leftAnchor, constant: CellConstants.textLeftAnchor).isActive = true
// Incorrect constraint
self.text.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor, constant: 40).isActive = true
解决方案
推荐阅读
- java - 与多个 testng 测试用例共享相同的数据提供程序,在从 excel 中读取第二个测试用例的数据时给出空指针异常
- owin - 如何使用 OWIN 托管多个 .Net-Core WebApi 在相同的 URL 下,所有 API 使用相同的中间件管道
- javascript - 当我从第一个表格中选择文本时更改另一个表格的背景
- c++ - Visual Studio C++ 仅使用环境变量添加标准标头位置
- php - 刷新页面后 Ajax 不适用于第一次 wordpress/woocommerce
- mysql - Laravel QueryBuilder - 相同查询的 `where()` 和 `whereRaw()` 结果不同
- java - 为什么“selectedCountry”、“selectedAge”、“selectedGender”返回null?
- javascript - 为每个数组项添加单击
- j - 这个空列表的第一个元素如何为 0?
- javascript - 如何在页面加载时随机播放视频?