UIScrollview calling superviews layoutSubviews when scrolling?

后端 未结 3 1809
走了就别回头了
走了就别回头了 2021-02-13 21:31

I added a UITableView as a subview to a custom UIView class I\'m working on. However I noticed that whenever I scroll the table it calls my classes layoutSubviews. I\'m pretty

3条回答
  •  既然无缘
    2021-02-13 22:00

    Yes, a UIScrollView does call layoutsubviews whenever it scrolls. I could've sworn this was stated in the documentation somewhere, but I guess not.

    Anyways, the prevailing idea for this is that a UIScrollView should layout its stuff so that views that currently can't be seen shouldn't be laid out. As users scroll in the scroll view, it should add and remove subviews as necessary. I'm guessing this is what TableViews use to enqueue table cells that get hidden.

    Is there any reason why you would care if layoutsubviews gets called or not?

提交回复
热议问题