当宽度约束设置动画时,UITextField具有黑色插图

时间:2016-05-29 04:50:17

标签: ios objective-c uitextfield

所以我通过调用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

enter image description here

1 个答案:

答案 0 :(得分:0)

将文本字段的内容模式设置为“重绘”:

View content mode in Interface Builder

如果您想在代码中执行此操作,请将文本字段的contentMode属性设置为UIViewContentModeRedraw