将子视图添加到当前视图,而不会弄乱视图中对象的定位 [英] Adding a subview to the current view without messing up positioning of objects in the view

查看:29
本文介绍了将子视图添加到当前视图,而不会弄乱视图中对象的定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何将 iADS 添加到应用程序的教程.本教程非常好,因为它适用于 iOS 3.0+.它可以在这里找到 http://www.raywenderlich.com/1371/how-to-integrate-iad-into-your-iphone-app

I am following a tutorial on how to add iADS to an app. This tutorial is pretty good since it accounts for iOS 3.0+. It can be found here http://www.raywenderlich.com/1371/how-to-integrate-iad-into-your-iphone-app

现在在教程中,步骤之一如下:

Now in the tutorial, one of the steps is the following:

"但是有一个简单的方法来修复它——我们只需将控件移动到子视图中即可!最简单的方法是将另一个视图从库中拖到 XIB 中,并将其大小更改为与现有视图的大小相同 (320×416).然后拖动现有视图作为新视图的子视图.完成后,它应该如下所示:

"But there’s an easy way to fix it – we’ll simply move the controls into a subview instead! The easiest way to do this is to drag another view from the library into the XIB, and change its size to be the same as the existing view’s size (320×416). Then drag the existing view as a subview of the new view. When you’re done, it should look like the following:

现在我的问题是,当我将这个新视图(子视图)添加到当前视图时,它不会扩展为如图所示的层次结构,直到我选择所有内容(图像、标签等)并手动拖动它进入这个新的子视图.这有效,但我对标签、图像等的定位已经丢失.一切都在字面上堆叠在彼此顶部的子视图的中心.我意识到本教程是在 xcode 3 中完成的,但是我可以做些什么来保持对象的位置?我在视图中有很多对象,重新定位它们会很痛苦.

Now my problem is when I add this new view (the sub view) to my current view, it does not expand into a hierarchy as shown in the picture until I select everything (images, labels, etc etc) and manually drag it into this new subview. This works BUT my positioning of labels, images etc etc has been lost. Everything is literally in the centre of the subview stacked on top of each other. I realize this tutorial was done in xcode 3 but is there something I can do to maintain position of my objects? I have many objects in the view and it would be such a pain to relocate them all again.

非常感谢!

推荐答案

您可以将现有的原始视图添加到另一个视图中,使您的原始视图成为子视图.这应该保持所有原始视图的子视图位置相同.

You could take your existing original view and add it into another view making your original the subview. This should keep all the original view's subviews position the same.

这篇关于将子视图添加到当前视图,而不会弄乱视图中对象的定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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