LoginSignup
6
6

More than 5 years have passed since last update.

UIPageViewController内のUITableViewやUICollectionViewのScrollsToTopsがうまく動かないメモ

Posted at

前提

scrollView.scrollsToTop = YES
とすることで、ユーザがステータスバーをタップした時にScrollView (UITableViewやUICollectionViewも含む)の先頭まで戻ることが出来る。

ただし、ひとつの画面の中に複数のScrollviewがあるとき、この設定は単に無視される。これはドキュメントにも明記されている "On iPhone, the scroll-to-top gesture has no effect if there is more than one scroll view on-screen that has scrollsToTop set to YES. (https://developer.apple.com/library/ios/documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html#//apple_ref/occ/cl/UIScrollView )"

さらにもうひとつ落とし穴があって、UIPageViewControllerの中に複数のViewControllerがある場合、現在見えてないViewについても"more than one scroll view on-screen"という制約に引っかかってしまうようだ。
例えば横からスライドで出てくるメニューバー的なものを、UITableViewを使ってオレオレ実装したりするとはまりやすい。

複数のScrollViewが同時に存在するときは、適切にscrollsToTopプロパティを設定して、ひとつだけYESになるようにしなくてはいけない。

6
6
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
6
6