[英]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.