2016-08-31 10 views
2

たとえば、特定のオフセットでスクロールするときにtableviewヘッダーの高さを変更する方法はありますか? これは私のヘッダーの実装です。私はヘッダーとしてカスタムセルを使用します。 しかし、私がやろうとしているのは、ある種のオフセットでスクロールしたときにヘッダーを表示して隠すことです。iOSスクロールスウィフトでUITableViewヘッダーの高さを変更する

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 
    let cell = tableView.dequeueReusableHeaderFooterViewWithIdentifier("tableViewHeader") as! MyTableViewHeaderCell 
    return cell 
} 

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 
    return 70 
} 

func scrollViewWillBeginDragging(scrollView: UIScrollView) { 
    if (scrollView.contentOffset.y>400){ 
    // i want to try to change the height of header to be 0/hidden 
} 
+0

ユーザーやテーブルがスクロールを停止するとどうなりますか? – ddb

+0

こんにちは@ddbは、オフセットが400を超えるときに表示したいオフセットに依存し、オフセットが400未満のときに非表示にします – Voyager

答えて

-1
 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 
      let cell = tableView.dequeueReusableHeaderFooterViewWithIdentifier("tableViewHeader") as! MyTableViewHeaderCell 
      return cell 
     } 

     func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 
      return headerHeight 
     } 

func scrollViewWillBeginDragging(scrollView: UIScrollView) { 

    if (scrollView.contentOffset.y > 400) { 
     headerHeight = 0.0; 

     if (isHidden == NO) { 

      isHidden = YES; 
      self.tableView.reloadData(); 
     } 

    } else { 
     headerHeight = 70.0; 

     if (isHidden == YES) { 

      isHidden = NO; 
      self.tableView.reloadData(); 
     } 
    } 
} 
0

私は、テーブルビューのヘッダー更新

func scrollViewWillBeginDragging(scrollView: UIScrollView) { 
    if (scrollView.contentOffset.y>400 && itWasLessThan400 == true) { 
     itWasLessThan400 = false 
     myTableView.reloadData() //or reload only the needed section if you have more than one sections 
    } else if (scrollView.contentOffset.y<400 && itWasLessThan400 == false) { 
     itWasLessThan400 = true 
     myTableView.reloadData() //or reload only the needed section if you have more than one sections 
    } else 
} 

を管理し、中viewDidLoaditWasLessThan400 = trueを設定してください保つために、ヘッダーの高さ

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 
    if (myScrollView.contentOffset.y>400){ 
     return 70 
    } else { 
     return 0 
    } 
} 

、これを処理するために、次のように行うだろうあなたのviewController

私はこれが助けてくれることを願っています:)

関連する問題