[英]UITableView Cell should not scroll horizontally swift iOS
不要在tableview中提供uiedgeinsets,而是在uitableview单元格中添加一个视图,覆盖整个单元格,并在该视图中添加另一个uiview,并从顶部底部前导尾部等于8或任何你想要的约束,然后单元格不会移动和你的tableview单元格看起来它有edgeinsets。
如果你正在使用AutoLayout,通过设置它只适用于你:
在代码中:
tableView.alwaysBounceVertical = false
或者在Interface Builder中:只需找到此选项并取消选中“Bounce Vertically”选项。
这是参考:
如果您没有使用AutoLayout:
override func viewDidLayoutSubviews() {
// Enable scrolling based on content height
tableView.isScrollEnabled = tableView.contentSize.height > tableView.frame.size.height
}
并尝试clipToBounds
tableview.clipsToBounds = true
您需要将clipsToBounds
属性设置为true
tableview.clipsToBounds = true
我通过下面的代码实现了我想要的。
postsTable.contentInset = UIEdgeInsets(top: 20, left: 20, bottom: 0, right: -20)
在UITableViewCell类中:
override var frame: CGRect{
get {
return super.frame
}
set(newFrame){
var frame = newFrame
frame.size.width = kScreenWidth - 40
super.frame = frame
}
}
现在,如果我向左或向右拖动单元格,它也会回到原始位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.