向下和向上滚动后,TableView单元格重叠UIView

时间:2016-08-31 16:17:49

标签: ios swift uitableview ios9 xcode7

我正在玩一些设计概念而且我遇到了这个“错误”。

知道为什么会这样吗?我已经迭代了不同的事情,仍然无法找到罪魁祸首或解决方案。

价格的这个“圆圈”与底部的另一个单元重叠是我的预期设计。这一切都很好,但是,当我向下滚动并向后滚动时,“较旧”的单元突然重叠“圆圈”。

请看截图。非常感谢任何帮助!!!

以前有没有人经历过这个?

iOS9 - Xcode 7.3.1

修改

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    if let cell = tableView.dequeueReusableCellWithIdentifier("CategoryCell") as? CategoryCell {

        cell.selectionStyle = .None
        cell.configureCell(dishes[indexPath.row])

        return cell

    } else {
        return UITableViewCell()
    }

}

Mobile Screenshot

编辑2: 经过进一步分析,我确信这与高度无关?我玩过不同的高度,但仍然得到相同的结果。

问题是,即使向下滚动它也能完美地加载,这一切都很好。直到我向上滚动,这就是问题开始出现的地方。

将剪辑子视图(单元格)设置为true将在加载时剪切所有内容,因此我将其设置为false。

剩下的问题是,如何在向上滚动时处理裁剪?

StoryBoard

编辑3: 我想我现在明白了这个问题,但我仍然不太确定如何解决它。

CircleView放置在一个与其下方的另一个单元格重叠的单元格上。设置clipsToBounds,height或将其置于前面对其下方的单元格没有影响,因为它在向上滚动时离开显示器。

任何人都知道如何以某种方式重新绘制它,就像它刚刚加载一样(因为onload,事情正在发挥作用)?或者在其他地方是否有clipToBounds设置我错过了?

我认为解决方案与此相关:How to stop UITableView from clipping UITableViewCell contents in iOS 7

但是,此解决方案不适用于ios9。

3 个答案:

答案 0 :(得分:5)

将单元格图层anchorPointZ设置为cellForRowAtIndexPath中的行索引:方法

cell.layer.anchorPointZ = indexPath.row;

答案 1 :(得分:0)

Have you tried setting an estimatedRowHeight for the tableView? Also, you can use the function heightForRowAtIndexPath and return UITableViewAutomaticDimension. That should automatically dimension every row to fill the circle size.

EDIT: If you want to bring the circle to the front of everything else, try this:

YourLabel.layer.zPosition = 1;
self.view.bringSubviewToFront(YourLabel);

答案 2 :(得分:0)

问题与细胞的高度有关。它不会为你动态调整。

您可以尝试将剪辑设置为tableView上的边界(查看屏幕截图)

clipsToBounds option