如何在Storyboard中使用UIScrollView [英] How to use UIScrollView in Storyboard

查看:701
本文介绍了如何在Storyboard中使用UIScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个滚动视图,其内容高度为1000像素,并希望能够在故事板上进行简单设计。

我知道它可以通过编程方式完成,但我真的很想能够直观地看到它。每次我在视图控制器上放置滚动视图时,它都不会滚动。是否有可能让它像我想要的那样工作或者我必须在代码中执行它?

I have a scroll view with content that is 1000px tall and would like to be able to lay it out for easy design on the storyboard.
I know it can be done programmatically but I really want to be able to see it visually. Every time I put a scroll view on a view controller it won't scroll. Is it possible to get it to work like I want or do I have to do it in the code?

推荐答案

我是回答我自己的问题,因为我花了2个小时才找到解决方案而StackOverflow允许这种QA风格。

I'm answering my own question because I just spent 2 hours to find the solution and StackOverflow allows this QA style.

这里开始完成如何使它在故事板中工作。

Start to finish here is how to make it work in storyboard.

1:转到您查看控制器并单击属性检查器

1: go to you view controller and click on Attribute Inspector.

2:将大小更改为自由格式而不是推断。

2: change Size to Freeform instead of Inferred.

3:转到主视图在那个故事板上,而不是你的滚动视图,而不是顶级视图。

3: Go to the main view on that storyboard, not your scrollview but rather the top level view.

4:点击尺寸检查器并设置此查看您想要的大小。我把我的身高改为1000.

4: Click Size Inspector and set this view to your desired size. I changed my height to 1000.

现在你会看到你的故事板有你的视图设置,所以你可以看到你的卷轴的整个高度,以便于设计。

Now you will see that you storyboard has your view setup so you can see the entire height of your scroll for easy design.

5:放在滚动视图上并拉伸它以便占据整个视图。您现在应该在视图控制器中的视图上有一个大小为320,1000的滚动视图。

5: Drop on a scrollview and stretch it so it takes up the whole view. You should now have a scrollview with size of 320,1000 sitting on a view in your view controller.

现在我们需要让它滚动并需要让它显示内容正确。

Now we need to make it scroll and need to make it show content correctly.

6:点击你的滚动视图,然后点击 Identity Inspector

6: Click on your scrollview and click on Identity Inspector.

7:添加用户定义的运行时属性,KeyPath为 contentSize ,然后输入SIZE和放入你的内容大小。对我来说它是(320,1000)。

7: Add a User Defined runtime attribute with KeyPath of contentSize then type of SIZE and put in your content size. For me it is (320, 1000).

因为我们想要在故事板上看到我们的整个滚动视图,我们将它拉伸,它的框架为320,1000但是为了在我们的应用程序中工作,我们需要将框架更改为可见的scrollview将是什么。

Since we want to see our whole scroll view on the storyboard we stretched it and it has a frame of 320,1000 but in order for this to work in our app we need to change the frame down to what the visible scrollview will be.

8:添加运行时属性,KeyPath frame ,类型为RECT,0,0,320,416。

8: Add a runtime attribute with KeyPath frame with Type RECT and 0,0,320,416.

现在我们运行我们的应用程序,我们将有一个可见的scrollview有一个0,0,320,416的框架,并可以向下滚动到1000.我们能够在故事板中布局我们的子视图和图像以及我们希望它们出现的方式。然后我们的运行时属性确保正确显示它。所有这一切都没有一行代码。

Now when we run our app we will have a visible scrollview has a frame of 0,0,320, 416 and can scroll down to 1000. We are able to layout our subviews and images and whatnot in Storyboard just the way we want them to appear. Then our runtime attributes make sure to display it properly. All of this without 1 line of code.

这篇关于如何在Storyboard中使用UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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