我希望在编辑开始时增加UITextField的大小,但是无法获得代码来执行此操作。
答案 0 :(得分:1)
在- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
中,将新帧大小设置为文本字段。然后拨打[textField setNeedsDisplay];
。
答案 1 :(得分:1)
Gomathi是对的。如果您想在编辑开始时扩展textFIeld并在编辑结束时再次收缩并且想要为其设置动画,则只需添加到他的答案中,您可能想要执行以下操作:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[UIView animateWithDuration:0.5 animations:^{
textField.frame = CGRectMake(textField.frame.origin.x-20, textField.frame.origin.y, textField.frame.size.width+40, textField.frame.size.height);
}];
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[UIView animateWithDuration:0.5 animations:^{
textField.frame = CGRectMake(textField.frame.origin.x+20, textField.frame.origin.y, textField.frame.size.width-40, textField.frame.size.height);
}];
[textField resignFirstResponder];
return YES;
}