xcode 将项目添加到故事板中的滚动视图(大小检查器似乎被锁定)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8947951/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:03:04  来源:igfitidea点击:

Adding items to scrollview in storyboard (size inspector appears to be locked)

iphonexcodeuiscrollviewstoryboard

提问by T.J.

I've added a scrollview with a content size that is larger than the screen size in my view controller using storyboard. Of course the purpose of the scrollview is to have content larger than the view that contains it. I would like to add buttons and label to the bottom of the scrollview graphically in storyboard, but I can't view that part of the scrollview. How do I get there. I tried adjusting in the size inspector which worked for me when I first added the view a few weeks ago, but it don't let me change anything.

我使用故事板添加了一个内容大小大于我的视图控制器中屏幕大小的滚动视图。当然,滚动视图的目的是让内容大于包含它的视图。我想在故事板中以图形方式将按钮和标签添加到滚动视图的底部,但我无法查看滚动视图的那部分。我如何到达那里。几周前我第一次添加视图时,我尝试调整对我有用的尺寸检查器,但它没有让我改变任何东西。

回答by livingtech

The only way I've been able to edit my content in a UIScrollView(and this dates back to way before the Storyboard, but I'm pretty sure it still applies) is to change the offset of the x or y of your content frame.

我能够在 a 中编辑我的内容的唯一方法UIScrollView(这可以追溯到故事板之前,但我很确定它仍然适用)是更改内容框架的 x 或 y 的偏移量。

Another option, depending on whether your content view is "static" (built in the .xib) or not, is to actually pull it outside of the scroll view, and set it as the content view programmatically in viewDidLoador something.

另一种选择,取决于您的内容视图是否是“静态”(内置在 .xib 中),实际上是将它拉到滚动视图之外,并以编程方式将其设置为内容视图viewDidLoad或其他内容。

Hope this helps, I can follow up with code examples if it makes sense and you need 'em.

希望这会有所帮助,如果有意义并且您需要它们,我可以跟进代码示例。

EDIT (2/10/2012): Here's an example of how to hook up the larger view to your scroll view. In this example, the scroll view (scrollView) is set to the view controller's view property. In the .xib I've also added a UIViewnamed largerView. The two are not hooked up in any way in the .xib file, they just both appear there.

编辑(2/10/2012):这是一个如何将较大视图连接到滚动视图的示例。在这个例子中,滚动视图 (scrollView) 被设置为视图控制器的 view 属性。在 .xib 中,我还添加了一个UIView命名为 largeView。这两者在 .xib 文件中没有以任何方式连接,它们只是出现在那里。

Given...

鉴于...

@property (nonatomic, retain) IBOutlet UIView *largeView;
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;

In viewDidLoad:we just...

viewDidLoad:我们只是...

// add the largeView to the main scrollView
[scrollView addSubview:largeView];
[scrollView setContentSize:largeView.frame.size];

This is probably the simplest possible example though. Good luck!

不过,这可能是最简单的示例。祝你好运!

回答by eugen

It's great that you solved that. If I had that problem I would create a view that has the same frame size as content size of the scroll view. Add all the controls I need (buttons, labels, textFields etc.) on this view at the positions I need. After that just added the view on scroll, make an IBOutlet of the scroll and set it's content size programmatically somewhere in my code, before using that scroll (setting it in viewDidLoad will be fine).

你解决了这个问题真是太好了。如果我遇到这个问题,我会创建一个与滚动视图的内容大小具有相同框架大小的视图。在此视图上我需要的位置添加我需要的所有控件(按钮、标签、文本字段等)。之后刚刚添加了滚动视图,在使用滚动之前(在 viewDidLoad 中设置它会很好),制作滚动的 IBOutlet 并在我的代码中以编程方式设置它的内容大小。

That's another solution of this problem.

这是这个问题的另一种解决方案。

回答by Mrunal

@T.J. & @livingtech:

@TJ & @livingtech:

Why don't you use embed property given in Interface Builder?

为什么不使用 Interface Builder 中提供的 embed 属性?

Here you are creating two views (UIView largeView and UIScrollView scrollView). So its kind of wasting of memory for the same objects.

在这里,您将创建两个视图(UIView largeView 和 UIScrollView scrollView)。因此,对于相同的对象,它会浪费内存。

enter image description here

在此处输入图片说明

  1. First add one more UIView in your nib with your height and width.
  2. Add your controls wherever you want. (let say largeViewonly)
  3. Then use embed property with ScrollView. (let say myScrollViewonly)
  4. Now add this myScrollViewin your original view wherever you want with your custom height and width.
  5. In code base just set myScrollViewcontentSize as per the largeViewsize.
  1. 首先在您的笔尖中添加一个具有您的高度和宽度的 UIView。
  2. 随心所欲地添加控件。(只说largeView
  3. 然后在 ScrollView 中使用 embed 属性。(只说myScrollView
  4. 现在将此myScrollView添加到您的原始视图中,任何您想要的自定义高度和宽度。
  5. 在代码库中,只需根据largeView大小设置myScrollViewcontentSize 。

This would be easier for the code reusability and expandability purpose. If in future you need to add more objects.

这对于代码可重用性和可扩展性来说会更容易。如果将来您需要添加更多对象。

回答by Berkay92

You can work on iPad Full Screen size if your content won't exceed the screen size too much.

如果您的内容不会超过屏幕尺寸太多,您可以在 iPad 全屏尺寸上工作。