0

我在情节提要中的某个位置设置了 UITextView。当应用程序首次加载时,我希望 textView 与它在情节提要中的位置不同。我通过将其框架设置为具有不同原点的不同框架以编程方式执行此操作(稍后 textView 将动画回原始位置)。但无论我怎么做,应用程序总是以 textView 在其故事板指定位置启动。我似乎无法在任何地方这样做...... viewDidLoad:,,viewWillAppear:没有任何效果。我怎样才能覆盖它?

另一件事......可以说 textView 的来源与其在故事板中的来源不同(框架在应用程序中的某个位置被重置)。如果我使用 向 textview 添加子视图,则 textView 将addSubView:重置为其在情节提要中的原始位置。为什么?!有什么办法可以阻止这一切?

4

2 回答 2

0

If you want to change the position of the textView when it starts up, I'd suggest that you do not have it in the storyboard and instead add it to the subview with its correct frame.

Especially with Autolayout in effect, having it there already means you would have to modify its constraints and if you're modifying its position programmatically already anyway, you might as well add it to the view programmatically too where you have more control over its constraints programmatically as well.

于 2014-01-04T18:46:36.940 回答
0

在自动布局下,您不能设置框架 - 好吧,您可以,但是一旦发生另一个布局传递,框架将重置为约束定义的框架。

使用自动布局更改您在界面构建器中布局的视图的大小或位置的最简单方法是创建各种约束的出口,然后编辑它们的constant属性。如果这不能给你足够的灵活性,你仍然需要约束的出口,但是当你想要移动东西时,你必须删除这些约束并添加新的约束。

于 2014-01-04T19:00:37.337 回答