Content of scrollview changes size when scrolling

六眼飞鱼酱① 提交于 2019-12-13 04:35:57

问题


I'm using iOS 6 and Xcode 4.6 and with the Interface Builder I added to my controller a UIScrollView that uses all the available space. In this UIScrollView I added some views (a UIImageView, a UITextView and a UITableView (I disabled the scrolling for the UITextView and the UITableView)).

In the :

- (void) viewDidLayoutSubviews;

method I resized all my views by increasing their height (to fit with their respective content). Then, I set the contentSize of my UIScrollView so that it fits with its content (my 3 views).

The resizing works and I can see them in my application when I run it. Also, the scrolling is good (the contentSize is correct as I can scroll).

However, I have one big issue : as soon as I scroll, my 3 views are resized to their initial size (instead of keeping the size I assigned them via the frame property).

All my views are added with Interface Builder to my storyboard.

Do you know what I did wrong? Why my UIScrollView's content is reseting its size when I scroll?

Thank you for your help


回答1:


You have auto layout enabled in your storyboard. When you scroll the scroll view, auto layout runs and resets your subview frames based on the constraints in the storyboard.

There are a few ways to fix this. One way is to turn off auto layout in your storyboard. Another way is to connect outlets to the constraints in your storyboard, and update the constraints (instead of setting the frames) to make auto layout put the views where you want them.



来源:https://stackoverflow.com/questions/17909062/content-of-scrollview-changes-size-when-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!