如何添加对象到UIScrollView扩展超出UIView从故事板? [英] How to add objects to a UIScrollView that extend beyond UIView from Storyboard?

查看:176
本文介绍了如何添加对象到UIScrollView扩展超出UIView从故事板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中的一个长的 UIScrollView 中有几个按钮和其他对象。在storyboard中,我添加了一个 UIScrollView 来填充entre视图,然后在我的.h文件中创建一个 IBOutlet 。我合成了我的.m文件中的滚动器,然后使用以下代码启动滚动器:

  @synthesize scroller = _scroller ; 
- (void)viewDidLoad
{
[super viewDidLoad];
[_scroller setScrollEnabled:YES];
[_scroller setContentSize:CGSizeMake(640,3000)];
}



现在我需要知道如何实际添加东西,到滚动区域延伸到你可以在视图中看到的区域。我的问题是,当我在故事板添加东西到我的视图,我只能添加东西,你可以看到在视图中,因此需要知道如何添加按钮到部分,我将滚动到!



希望这很清楚。非常感谢您的帮助!

解决方案

UPDATE





我将视图控制器的大小从Inferred更改为Freeform。然后我把它的视图的高度从460改为800.(顺便说一下,control-shift-click给你一个光标下的所有对象的菜单。)



发生在我在模拟器中运行它时:





如您所见,视图层次已调整为适合屏幕,但 UIScrollView 的子视图未重新定位,滚动视图设置其内容大小适当。 (这可能只能与autolayout正常工作,但...)


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...)

这篇关于如何添加对象到UIScrollView扩展超出UIView从故事板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆