我明白這個問題非常常見,而且我已經閱讀了很多答案,但無法理解代碼是如何工作的。這工作:iPhone在鍵盤打開時向上滾動視圖
-(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];
}
}
}
我沒有正確使用此功能?
見下文剝奪自己的答案 - 似乎完美地覆蓋它。 – Andiih 2010-05-12 08:40:21