Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top