【发布时间】:2012-11-04 19:19:57
【问题描述】:
我遇到了一个特殊的问题。我有两个 UITextFields 的视图,它们以 280px 宽开始。在焦点上,我希望它们缩短以显示一个按钮 - 我正在使用以下代码:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
CGRect revealButton = CGRectMake(textField.frame.origin.x, textField.frame.origin.y, 221, textField.frame.size.height);
[UIView beginAnimations:nil context:nil];
textField.frame = revealButton;
[UIView commitAnimations];
NSLog(@"%f",textField.frame.size.width);
}
编辑结束后,他们应该回到原来的帧:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
CGRect hideButton = CGRectMake(textField.frame.origin.x, textField.frame.origin.y, 280, textField.frame.size.height);
[UIView beginAnimations:nil context:nil];
textField.frame = hideButton;
[UIView commitAnimations];
}
我第一次关注文本字段时,它工作得很好。但是,如果我在关注其他内容之后关注第一个文本字段(例如,如果我最初关注第一个文本字段,关注第二个,然后重新关注第一个,或者如果我最初关注第二个然后关注第一个),它根本不会改变它的框架。更令人费解的是,它将记录 221 作为其宽度 - 它只是不会在屏幕上显示。此外,此问题不适用于第二个文本字段。
有什么想法吗?提前谢谢...
【问题讨论】:
标签: iphone objective-c ios uitextfield frame