Why UIScrollView can not scroll once dragging UIButton or UILabel from storyboard

211 views Asked by At

I got the same issue here

The UIScrollView can scroll when adding button or label via code, but failed when adding from the storyboard or xib.

Setting the contentSize from the viewDidAppear can resolve this issue.

Set up the contentSize from viewDidLoad can not work. Question here is to figure out why ? I hope someone can explain the insider magics or this is just a bug of UIScrollView. I think it should not be designer like this way.

1

There are 1 answers

0
Yoav Schwartz On BEST ANSWER

The reason it doesn't work in ViewDidLoad is that all the sizes are not yet final there, in fact, Im betting it would also not work in viewWillAppear.Im guessing you are not liking making the change in viewDidAppear as it is visible to the user. The correct place to set the size is viewWillLayoutSubviews. The flow is

viewDidLoad
viewWillAppear
viewDidLayoutSubviews
viewDidApear

I suggest you reread those methods in the documentation.