一、TableViewCell使用約束自適應(yīng)高度的幾種方式
1廓块、//使用TABLEVIEW自帶方法來自適應(yīng)高度
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
//自適應(yīng)高度
table_view.rowHeight=UITableViewAutomaticDimension
二、TableView向下滑動后頂部無法再滑回初始狀態(tài)
self.automaticallyAdjustsScrollViewInsets = false
三带猴、TableView無內(nèi)容時取消分割線
table_view.tableFooterView = UIView()
四昔汉、uitableview刷新CELL的兩種方式
1、用reloaddata來刷新全部CELL從而達到局部改變某些CELL樣式拴清、內(nèi)容等或者全部重新加載靶病;reloaddata不會改變CELL在屏幕中顯示的位置;
2口予、tableView.beginUpdates()和tableView.endUpdates()采用動畫式來reloadrow而不是reloadtableview娄周。詳解 http://www.cnblogs.com/breezemist/p/3538673.html?
五、UITableView繼承了ScrollView的滾動特性沪停,從而可以在tableview中添加滾動動畫之類的動態(tài)效果
func scrollViewDidScroll(scrollView:UIScrollView) {
//出現(xiàn)在屏幕中的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
}
}