2017-07-26 32 views
2

是否可以給ui tableview中的部分標題偏移以編程方式停止?UITableView部分標題停止位置

那麼,部分標題從頂部停止100 px?

+0

檢查這個https://stackoverflow.com/questions/23969587/is-it-possible-to-have-a-fixed-uitableview-header-while-使用部分 – Rex

回答

3

我認爲這應該工作:

override func scrollViewDidScroll(_ scrollView: UIScrollView) 
{ 
    super.scrollViewDidScroll(scrollView) 
    let inset: CGFloat = 73 
    if scrollView.contentOffset.y < inset && scrollView.contentOffset.y > 0 { 
     scrollView.contentInset = UIEdgeInsets(top: scrollView.contentOffset.y, left: 0, bottom: 0, right: 0) 
    } else { 
     if scrollView.contentOffset.y < 0 { 
      scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) 
     } else { 
      scrollView.contentInset = UIEdgeInsets(top: inset, left: 0, bottom: 0, right: 0) 
     } 
    } 
} 
+1

謝謝,它適用於我的問題:-) – auryn31

0

您可以使用UIScrollView的屬性:contentInset。風格爲表格視圖UITableViewStyleGrouped (.group in Swift)。 這是我這樣的UI的例子: enter image description here

如果你想避免頭部移動,設置Bounce Vertical屬性設置爲NO。

+0

感謝您的評論,UIEdgeInsets使標題正確的東西,但內容也得到了偏移量,但我只想停止標題,因爲tableview是在一個透明的視圖後面 – auryn31

0

你可以試試這個

CGFloat newViewHeight = 40; 

UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, newViewHeight)]; 

self.tableView.tableHeaderView = newView; 
self.tableView.contentInset = UIEdgeInsetsMake(-newViewHeight, 0, 0, 0); 

節頭現在將滾動就像任何普通的細胞。

+0

沒有工作,對不起: - ( – auryn31