问题描述
我想在我的应用程序的长 UIScrollView
中有几个按钮和其他对象.在情节提要中,我添加了一个 UIScrollView
来填充整个视图,然后在我的 .h 文件中创建了一个 IBOutlet
.我在我的 .m 文件中合成了滚动条,然后使用以下代码启动滚动条:
@synthesize 滚动条 = _scroller;- (void)viewDidLoad{[超级视图DidLoad];[_scroller setScrollEnabled:YES];[_scroller setContentSize:CGSizeMake(640, 3000)];}
所以现在我需要知道如何将按钮等内容实际添加到滚动条区域,该区域延伸到您在视图中可以看到的区域下方.我的问题是,当我在情节提要的视图中添加按钮时,我只能将内容添加到您在视图中可以看到的内容,因此需要知道如何将按钮添加到我将滚动到的部分!
希望这很清楚.感谢您的所有帮助!
更新
我发布了
我将视图控制器的大小从Inferred"更改为Freeform".然后我将其视图的高度从 460 更改为 800.(顺便说一下,control-shift-click 会为您提供光标下所有对象的菜单.)
当我在模拟器中运行它时会发生以下情况:
如您所见,视图层次结构已调整大小以适应屏幕,但 UIScrollView
的子视图没有重新定位,并且滚动视图适当地设置了其内容大小.(不过,这可能只适用于自动布局......)
I want to have several buttons and other objects in a long UIScrollView
in my app. In storyboard, I added a UIScrollView
to fill the entre view, and then created an IBOutlet
in my .h file. I synthesized the scroller in my .m file, and then used the following code to start the scroller:
@synthesize scroller = _scroller;
- (void)viewDidLoad
{
[super viewDidLoad];
[_scroller setScrollEnabled:YES];
[_scroller setContentSize:CGSizeMake(640, 3000)];
}
So now I need to know how to actually add things, such as buttons, to the area of the scroller that extends below what you can see in the view. My problem is that as I add butons to my view in storyboard, I can only add things to what you can see in the view, and therefore need to know how to add buttons to part that I will scroll to!
Hopefully this is clear. Thanks for all your help!
UPDATE
I have posted a screencast that walks through this technique step-by-step.
ORIGINAL
The easiest way to handle this is simply to make the view in your storyboard taller. When the app runs, any of the normal container view controllers (UINavigationController
, UITabBarController
, UISplitViewController
, or even UIViewController
when it's the root view controller of its window) will resize the view to fit on the screen and scroll.
Here's an example of how to set it up in Xcode:
I changed the view controller's size from "Inferred" to "Freeform". Then I changed its view's height from 460 to 800. (By the way, control-shift-click gives you a menu of all objects under the cursor.)
Here's what happens when I run it in the simulator:
As you can see, the view hierarchy was resized to fit the screen, but the subviews of the UIScrollView
weren't repositioned, and the scroll view set its content size appropriately. (That may only work properly with autolayout, though...)
这篇关于如何将对象添加到超出 Storyboard 的 UIView 的 UIScrollView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!