动态更改位置

时间:2016-07-31 08:55:16

标签: ios objective-c mobile uitextview

我是IOS开发的新手,所以当我动态更改UITextFeild的宽度时,我希望下面的按钮向上移动。 我尝试使用约束但它似乎没有动态转移。

 (IBAction)selectStatus:(id)sender {
    CGRect frameRect = _textViewDevices.frame;
    frameRect.size.height = 10; 
    self.textViewDevices.frame = frameRect;

如何实现这一目标的任何好例子?

我想实现类似于android中的相对定位。

current box before any action on action the box size change

2 个答案:

答案 0 :(得分:2)

尝试在修改后调用layoutIfNeeded

- (IBAction)selectStatus:(id)sender {
    CGRect frameRect = _textViewDevices.frame;
    frameRect.size.height = 10; 
    self.textViewDevices.frame = frameRect;
    [self.view layoutIfNeeded];
}

如果文本视图上有高度约束,请尝试设置其常量而不是设置框架高度:

- (IBAction)selectStatus:(id)sender {
    self.textViewHeightConstraint.constant = 10;
    [self.view layoutIfNeeded];
}

答案 1 :(得分:0)

当第一个紫色字段的高度发生变化时,以编程方式使下面的所有视图保持在其旁边,您应该正确更新frame.origin.y

因此,例如,状态标签应该像这样重新构建

CGRect frame = statusLabel.frame;
frame.origin.y = firstField.origin.y + firstField.size.height + 5;
statusLabel.frame = frame;

对于以下所有视图都是一样的(我认为视图之间有5个像素的空间)

相关问题