我有一个非常简单的UIScrollView与一些内容(许多子视图)。这个滚动视图用于显示用户创建的一些帖子(图片+文字)。其中一种观点实际上是作者的形象,它溢出了底部细胞的界限。因此它与后面的单元格重叠,并使用clipToBounds = false
我可以获得所需的结果。如果我向下滚动,一切都很好。当我开始向前滚动时,以前覆盖的视图会被剪切。dequeueReusableCell休息cliptobounds
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);
}
看来,双端队列操作打破我做了(使用自动版式)的布局。我试过很多解决类似这样的
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.contentView.superview?.clipsToBounds = false;
cell.clipsToBounds = false;
cell.contentView.clipsToBounds = false;
}
但结果看起来总是相同的。每行的高度是固定的。
嗨,这是一个伟大的提示,它似乎工作,但相反方向。现在它在我向上滚动时起作用,但是当我向下滚动时不起作用,因为在首先布局单元时,也会调用'willDisplayCell'。 –
@DiegoViganò,检查我的更新答案。 – dive
G R E A T!有效!我欠你一杯啤酒!再次感谢! –