使用自动布局修复视图的位置

时间:2017-08-26 08:01:47

标签: ios uitableview autolayout ios11 uitableviewrowaction

下面的代码可以在iOS 10中使用。我可以将单元格向左滑动并保留其“技巧”。固定在UITableView的边缘。但它在iOS 11中不起作用。(滑动动画由UITableViewRowAction完成)

如果有人知道如何在iOS 11上运行,我将不胜感激。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "CellId", for: indexPath) as! SomeBeautifulCell
    if cell.fixedLeadingConstraint == nil {
         let constraint = NSLayoutConstraint(item: cell.trickView, attribute: .leading, relatedBy: .equal, toItem: tableView, attribute: .leading, multiplier: 1, constant: 10)
                cell.fixedLeadingConstraint = constraint
        DispatchQueue.main.async {
            tableView.addConstraint(constraint)
        }
    }      
    return cell
}

0 个答案:

没有答案