34
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UITableView の tableHeaderView の高さをアニメーションつきで変更する

34
Posted at

UITableView の tableHeaderView の高さをアニメーションつきで変更する

問題点

UITableView の tableHeaderView は、単純に

self.tableView.tableHeaderView.frame.size.height = 500

としても値は変更されません。

対応策

下記のように、いったん別Viewに代入し、tableHeaderViewに再び代入すれば変更できる。

let headerView = self.tableView.tableHeaderView as UIView!

headerView.frame.size.height = 500
self.tableView.tableHeaderView = headerView

アニメーションつきで変更する

let headerView = self.tableView.tableHeaderView as UIView!
UIView.animateWithDuration(1.0, delay: 0.0, options: nil,
  animations: { () -> Void in
    headerView.frame.size.height = 500
    self.tableView.tableHeaderView = headerView
  }, completion: { (finished) -> Void in
    // do something
})

アニメーションつきで消す場合はこんな感じになるかと思います。

34
36
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
36

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?