如何将对象添加到从 Storyboard 扩展到 UIView 之外的 UIScrollView? [英] How to add objects to a UIScrollView that extend beyond UIView from Storyboard?

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

问题描述

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

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

所以现在我需要知道如何将按钮之类的东西实际添加到滚动条的区域,该区域延伸到您在视图中可以看到的区域下方.我的问题是,当我在情节提要中向视图添加按钮时,我只能向视图中可以看到的内容添加内容,因此需要知道如何向我将滚动到的部分添加按钮!

希望这很清楚.感谢您的帮助!

解决方案

UPDATE

我发布了

我将视图控制器的大小从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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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