iOS UIScrollView with autosizable content
Is it true the UIScrollView
should have only one UIView
inside? Using addSubview
method you can add m开发者_如何学Goultiple elements inside.
QUESTION:
I'm adding elements directly to the scroll view. Assume the contentSize
of the scroll view is 1000px height. I add a UIButton
on it and place it at the bottom with autoresizingMask = UIViewAutoresizingFlexibleTopMargin
. If I extend the height of the content to 2000px I would like this button to stay at the bottom. How can I achieve this when adding elements directly to the scroll view?
Thx!
A UIScrollView
can have as many subviews as you want. Just add them and update contentSize
properly.
When zooming in a scroll view there is however only a single subview that will be zoomed. So if you intend for zooming content, then a single subview is what you want.
To you first question, no -- UIScrollView
can have as many subviews as you want. Typically you keep track of which subviews you have put into the scrollview so that you can remove them when they are not visible (and save some memory). This is pretty much the point of UIScrollView
.
To your second question, YMMV, but in my experience UIScrollView
doesn't seem to pay attention to the autoresizingMask
attribute of its subviews, so you wil have to manually keep your UIButton pinned towards the bottom of your UIScrollView
as you change its size -- wherever you set the UIScrollView
's contentSize is the spot to adjust your UIButton
's frame.
精彩评论