所以我通过调用UITextField
中的[self viewLayoutIfNeeded]
来更改[UIView animateWithDuration:]
的宽度限制。文本字段宽度约束的起始宽度为20,然后我将其重置为250,并调用viewLayoutIfNeeded
。当发生这种情况时,它会适当调整大小,但两边都有奇怪的黑色内嵌。我没有使用阴影或任何东西。有没有人处理过此问题或有解决方案?
视图在我的故事板中设置,我为宽度约束拖动NSLayoutConstraint
,这是唯一被改变的属性。
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textFieldWidthConst;
@end
@implementation ViewController
-(void)viewDidAppear:(BOOL)animated {
[self.view layoutIfNeeded];
_textFieldWidthConst.constant = 275;
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
[self.view layoutIfNeeded];
} completion: nil
}];
}
@end