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

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

有什么好的例子可以实现吗?

我想要实现类似android中的相对定位的功能。

current box before any action
ios - 动态改变位置-LMLPHP

最佳答案

修改后尝试调用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];
}

关于ios - 动态改变位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38682357/

10-12 02:46
查看更多