這是我如何實現我的代碼:
1)我的看法是一個UIScrollView。
2)我在我的視圖中有多個UITextField,並使用標籤ID來區分它們。當用戶點擊一個的UITextField,該委託被稱爲移動的UIScrollView:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
switch (textField.tag)
{
case 0:
[myScrollView setContentOffset:CGPointMake(0, 18) animated:YES];
break;
case 1:
[myScrollView setContentOffset:CGPointMake(0, 56) animated:YES];
break;
case 2:
[myScrollView setContentOffset:CGPointMake(0, 94) animated:YES];
break;
case 3:
[myScrollView setContentOffset:CGPointMake(0, 132) animated:YES];
break;
case 4:
[myScrollView setContentOffset:CGPointMake(0, 170) animated:YES];
break;
case 5:
[myScrollView setContentOffset:CGPointMake(0, 208) animated:YES];
break;
case 6:
[myScrollView setContentOffset:CGPointMake(0, 246) animated:YES];
break;
case 7:
[myScrollView setContentOffset:CGPointMake(0, 284) animated:YES];
break;
case 8:
[myScrollView setContentOffset:CGPointMake(0, 322) animated:YES];
break;
default:
break;
}
return YES;
}
3)我也有UITextView的,並使用該委託來達到同樣的效果:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
if(textView.tag == 0)
{
[myScrollView setContentOffset:CGPointMake(0, 360) animated:YES];
// do some stuff...
}
if(textView.tag == 1)
{
[myScrollView setContentOffset:CGPointMake(0, 504) animated:YES];
// do some stuff...
}
return YES;
}
注意: CGPointMake(0, 123)
值取決於您自己的文本字段座標。
更改視圖的框架與鍵盤的框架 – 2013-05-10 12:17:15