xcode 使我的 UIView 可滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14439559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make my UIView Scrollable
提问by Zindokar
I know that I have to insert a UIScrollView in my UIView and in my viewLoad put the sizeContent of my IBOutlet UIScrollView, but I have some doubts because it doesn't work for me, I guess that there is some information missing for me.
我知道我必须在我的 UIView 中插入一个 UIScrollView,并在我的 viewLoad 中放置我的 IBOutlet UIScrollView 的 sizeContent,但我有一些疑问,因为它对我不起作用,我想我缺少一些信息。
My UIView size is 320x678, so I need to scroll it down/up vertically, I googled but some methods but always crash or doesn't work, I deploy target to iOS 4.3 in order that my app work for all iOS >= 4.3, and I'm at this point that need help to clarify my mind...
我的 UIView 大小是 320x678,所以我需要垂直向下/向上滚动它,我用谷歌搜索但有些方法总是崩溃或不起作用,我将目标部署到 iOS 4.3 以便我的应用程序适用于所有 iOS >= 4.3,我现在需要帮助来澄清我的想法......
What steps should I take from the begining to the end? and the scroll view should be on the foreground or background of all controller?
从开始到结束我应该采取哪些步骤?滚动视图应该在所有控制器的前景还是背景上?
EDIT: I did this....
编辑:我这样做了....
|-button-||-imgview-||-button-| |-some-|
|-------scrollview content size--------| Size = 320x678
|--------------scrollview--------------| Size = 320x678
|----------------view------------------| Size = 320x678
And probabbly that's my mistake, but, why I cannot make my iPhone scrollable?
可能那是我的错误,但是,为什么我不能让我的 iPhone 滚动?
|-----iPhone screen-----|
|-------------My app------------|
If I don't do any kind of trick to scroll I won't see more than my iPhone screen, there is not any autoscroll for that kind of "problems"? or I have to do that you told me?
如果我不做任何滚动技巧,我将不会看到比 iPhone 屏幕更多的东西,这种“问题”没有任何自动滚动?或者我必须做你告诉我的?
Because now my problem is that I have to rebuild my .xib and I really don't understand how to do it, the theory I understand but not how to.
因为现在我的问题是我必须重建我的 .xib 并且我真的不明白如何去做,我理解的理论但不知道如何去做。
EDIT2:
编辑2:
I fixed following your theory.
我按照你的理论固定。
1.- I created a Iphone screen 3.5
2.- I created an auxiliar view with freeform and adapted to 320x678
3.- I designed my 320x678 view
4.- In my main .xib I added my scroll IBOutlet and in the IB then linked.
5.- On my loadview I added the sizecontent
6.- I dragged to my 3.5 screen all the content from my auxiliar window.. then I deleted the auxiliar window.
Thanks.
谢谢。
回答by Fogmeister
I think you've got your scroll view ideas the wrong way around.
我认为您的滚动视图想法是错误的。
In order to use a scroll view you add it to a view that doesn't scroll. i.e. yourViewController.view
. Then you add the content into your scrollView
and set the contentSize
of the scrollView
.
为了使用滚动视图,您将其添加到不滚动的视图中。即yourViewController.view
。然后添加内容到您scrollView
,并设置contentSize
的scrollView
。
The ScrollView
contains its own view that does the scrolling.
将ScrollView
包含自己的观点,即不滚动。
i.e.
IE
|-button-| |-button-| |--label--|
|-------scrollview content size--------| Size = 320x678
|--scrollview----| Size = 320x480
|------view------| Size = 320x480
This will then show one and a half buttons but allow you to scroll so you can see the label too.
这将显示一个半按钮,但允许您滚动以便您也可以看到标签。
I hope this makes sense.
我希望这是有道理的。