一、TableViewCell使用約束自適應高度的幾種方式
1、//使用TABLEVIEW自帶方法來自適應高度
lettestValue:NSString="aaaaaaaa"
functableView(tableView:UITableView, heightForRowAtIndexPath indexPath:NSIndexPath) ->CGFloat{
letattr = [NSFontAttributeName:UIFont.systemFontOfSize(17)]
returntestValue.boundingRectWithSize(CGSizeMake(300,0), options: .UsesLineFragmentOrigin, attributes: attr, context:nil).size.height
}
2、使用兩行代碼搞定
//初始高度60
table_view.estimatedRowHeight=60
//自適應高度
table_view.rowHeight=UITableViewAutomaticDimension
二、TableView向下滑動后頂部無法再滑回初始狀態
self.automaticallyAdjustsScrollViewInsets = false
三、TableView無內容時取消分割線
table_view.tableFooterView = UIView()
四、uitableview刷新CELL的兩種方式
1、用reloaddata來刷新全部CELL從而達到局部改變某些CELL樣式、內容等或者全部重新加載;reloaddata不會改變CELL在屏幕中顯示的位置;
2、tableView.beginUpdates()和tableView.endUpdates()采用動畫式來reloadrow而不是reloadtableview。詳解 http://www.cnblogs.com/breezemist/p/3538673.html?
五、UITableView繼承了ScrollView的滾動特性,從而可以在tableview中添加滾動動畫之類的動態效果
func scrollViewDidScroll(scrollView:UIScrollView) {
//出現在屏幕中的cells visibleCells
forcellintableView.visibleCells{
letbottomView = cell.contentView.viewWithTag(2000)
letimage = bottomView?.viewWithTag(2001)
letrect = bottomView?.convertRect((bottomView?.bounds)!, toView:nil)
varY =UIScreen.mainScreen().bounds.size.height- (rect?.origin.y)! -600
Y*=0.2
ifY>0{
Y=0
}
ifY < -100{
Y = -100
}
image?.frame.origin.y= Y
}
}