【发布时间】:2010-05-11 18:06:05
【问题描述】:
我知道这个问题非常普遍,我已经阅读了很多答案,但无法理解代码的工作原理。这有效:
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
if ([sender isEqual:txtLeaveAddyLine1])
{
//move the main view, so that the keyboard does not hide it.
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
}
}
在这个例子中,txtLeaveAddy 是第一个被键盘隐藏的 UITextField,它的作用就像一个魅力。当我循环浏览屏幕上的文本字段时,当用户进入该 txtLeaveAddyLine1 字段时,它会向上滚动。但是,当我尝试在 txtLeaveAddyLine1 字段下方添加字段时 - 没有任何反应。例如:
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
if ([sender isEqual:txtLeaveAddyLine1])
{
//move the main view, so that the keyboard does not hide it.
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
}
if ([sender isEqual:txtLeaveAddyLine2])
{
//move the main view, so that the keyboard does not hide it.
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
}
}
我没有正确使用这个功能吗?
【问题讨论】: