将元素添加为subView后,元素位置会发生变化

时间:2014-01-10 07:08:19

标签: objective-c xcode uiview xcode5

我将UITextFieldUITextView和另一个元素添加到UIView,并在 Xcode 效用区中设置其位置>。我想要做的是将它们分组为subView并将一些动画应用于subView。 但是在将它们添加到新创建的subView之后,请更改它们的位置,查看这些图片(添加它们之前和之后):
之前
Before

After
绿色UITextField居中对齐,UITextView消失! (我现在不关心UILabel和那条水平线)。
这是我的代码:

    CGRect oldPosition = taskTitle.frame;

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
    [view setBackgroundColor:[UIColor redColor]];

    [view addSubview:taskTitle];
    [view addSubview:taskNote];
    [view addSubview:datePickerButton];

    taskTitle.frame=oldPosition;
    [self.view addSubview:view];

1 个答案:

答案 0 :(得分:0)

在“工具栏”栏中禁用文件检查器中的自动布局。 可以通过取消选中使用Autolayout选项来完成。

以下是截图:

enter image description here