- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个非常简单的 UIScrollView,其中包含一些内容(许多 subview )。此 ScrollView 用于显示用户发布的一些帖子(图片+文本)。其中一个 View 实际上是作者的图像,它溢出了底部单元格边界。因此它与后面的单元格重叠,使用 clipToBounds = false
我能够获得所需的结果。如果我向下滚动,一切都很好。当我开始向上滚动时,之前覆盖的 View 现在被剪掉了。
Cell overlapping working fine Cell overlapping not working (when I scroll up)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = (indexPath.row % 2 == 0) ? "FeedCellLeft" : "FeedCellRight";
let cell = feedScrollView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! FeedCell;
self.setUpCell(cell, atIndexPath: indexPath);
return cell
}
setUpCell
函数只是执行一些与 UI 相关的任务
let row = indexPath.row
cell.postImage.downloadImageFrom(link: rows[row].image, contentMode: .scaleToFill)
cell.postAuthorImage.downloadImageFrom(link: "https://pbs.twimg.com/profile_images/691867591154012160/oaq0n2zy.jpg", contentMode: .scaleToFill)
cell.postAuthorImage.layer.cornerRadius = 22.0;
cell.postAuthorImage.layer.borderColor = UIColor.white.cgColor
cell.postAuthorImage.layer.borderWidth = 2.0;
cell.postAuthorImage.layer.masksToBounds = true;
cell.selectionStyle = .none
cell.postData.layer.cornerRadius = 10.0;
cell.contentView.superview?.clipsToBounds = false;
cell.clipsToBounds = false;
if (indexPath.row % 2 != 0) {
cell.postData.transform = CGAffineTransform.init(rotationAngle: (4 * .pi) / 180);
} else {
cell.postData.transform = CGAffineTransform.init(rotationAngle: (-4 * .pi) / 180);
}
deque 操作似乎破坏了我所做的布局(使用自动布局)。我试过很多这样的解决方案
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.contentView.superview?.clipsToBounds = false;
cell.clipsToBounds = false;
cell.contentView.clipsToBounds = false;
}
但结果看起来总是一样的。每行的高度是固定的。
最佳答案
我认为问题在于 subview 的层次结构。当您向下滚动时,您的单元格从上到下出队并以相同的顺序添加到 UITableView
并且一切看起来都很好。因为前一个单元格在 View 层次结构中位于以下单元格之上。但是当你向上滚动时,单元格从下到上出列,这意味着顶部的单元格在前一个单元格的“后面”。您可以使用 Debugging View Hierarchies 轻松查看它Xcode 的功能。
你可以尝试 bringSubviewToFront:
例如:
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.superview.bringSubview(toFront cell)
}
Updated version
我在 Playgrounds 中做了一些小的研究,发现只有一个合理的选择可以实现重叠单元而不会出现巨大的性能问题。该解决方案基于 cell.layer.zPosition
属性并且工作正常(至少在我的 Playground 中)。我用以下代码更新了 willDisplay cell:
中的代码:
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.layer.zPosition = (CGFloat)(tableView.numberOfRows(inSection: 0) - indexPath.row)
}
根据 .zPosition
( Apple Developer Documentation ) 的文档:
The default value of this property is 0. Changing the value of this property changes the the front-to-back ordering of layers onscreen. Higher values place this layer visually closer to the viewer than layers with lower values. This can affect the visibility of layers whose frame rectangles overlap.
所以我使用当前的 dataSource
计数器作为 minuend 和当前单元格的 indexPath.row
作为 subtrahend 到为每个单元格计算层的 zPosition
。
You can download full version of my playground here.
关于ios - dequeueReusableCell 打破 cliptobounds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40684687/
根据官方文档,有两种方法可以从tableView的队列中获取可重用的cell。一个是 dequeueReusableCell(withIdentifier:for:),另一个是 dequeueReus
如您所知,如果不以某种方式重置tableViewCells,则在上下滚动后可能会错误显示。在网上搜索但没有找到满意的答案后,我想知道该怎么做。 我正在使用一个带有可重复使用的标识符的prototype
无法理解 UITableview 对“dequeueReusableCell”方法的调用。 UITableview 中的 dequeue 过程是如何发生的?我们是获得可重复使用的电池还是总是获得新电池
我正在创建一个类似于 bbc 应用程序的 iOS 应用程序- 我有一个表格 View ,有两个部分- 第一部分包含包含 ScrollView 宽图像的单元格- 第二部分包含可扩展单元格,其中包含 Sc
我有一个 tableView 是这样设置的: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSInd
我在一个列表中使用了一个dequeueReusableCell,单元格中有4个UILabel。下面有截图。 凡是有“-”字头的标签,都是红色的,但翻了几页,数字就乱七八糟了。想知道是否有办法避免这种情
我有一个 Collection View ,我正在为单元格使用一个自定义类。每个单元格都有两个 TextView ,chapterTitleTextView 和 chapterBodyTextView
我是 iOS 编程领域的新手,我最近在网上看到了一些实现的代码示例,例如: functableView(_ tableView: UITableView, cellForRowAt indexPath
我在 Swift 上使用表格和单元格时遇到问题。 我创建了一个简单的 UITableViewController,其中包含两部分静态单元格。 回顾一下: 1 个表格 View 2 个部分 4 个单元格
我有一个数组,我将其显示为 dequeueReusableCell,我想在单元格旁边显示适当的图像。我的图像与位于 Assets 中的数组中的项目同名。 如何在 dequeueReusable 单元格
我正在使用自动填充实现搜索。我有 UITextField 和 UITableView。当用户更改文本字段中的文本时,我从服务器加载新数据并将其显示在表格 View 中。 结果的数量是固定的(5 个或更
好的,情况如下: 我有一个 Collection View ,在 cellForRow 中,我使用 dequeueReusableCell 来重用单元格。在每个单元格上,我都有一个自定义 UIView
当我们越过特定数量的行时,我想在自定义单元格中隐藏一些元素。我添加了比可见行更多的行,因为我需要滚动到没有弹跳效果的最后一行。但是现在我有更多的单元格,我不需要行 > 13 之后的单元格。 我尝试用
不断收到此错误: 'Editor placeholder in source file' 在 tableView.dequeueReusableCell 行上,不知道哪里出了问题。请帮助如何摆脱这个错
我现在有一个表格 View ,它被设置为像 Netflix 或 Spotify 侧 ScrollView 一样工作。为此,我向每个单独的表格单元格添加了一个 ScrollView ,该表格单元格包含列
我有一个数组,我为每个数组项创建了一个单独的 vc,tableView.dequeueReusableCell 显示错误的 vc。我读到这是因为该单元格是可重复使用的,并且它保留了先前选择的数组中的数
我有一个非常简单的 UIScrollView,其中包含一些内容(许多 subview )。此 ScrollView 用于显示用户发布的一些帖子(图片+文本)。其中一个 View 实际上是作者的图像,它
我正在尝试使用 UITableView 制作列表并收到错误消息: [UITableView] 没有成员“dequeueReusableCell” 我创建了一个带有原型(prototype)单元格的表
在 viewDidLoad 中,我像这样注册单元格: let cellIdentifier = "Cell" override func viewDidLoad() { super.viewD
我们已经设置了我们的 tableviewSource 和一个 tableview,但是在滚动大量单元格时,数据出现在错误的单元格中并且选择状态被应用于多个单元格时遇到了问题。 表格单元格根据 n+1
我是一名优秀的程序员,十分优秀!