を使用し、scrollView他の UI 要素を のサブビューとして作成する必要がありScrollViewます。また、 のフレーム サイズscrollViewもウィンドウ全体のサイズを使用するLandscape Mode必要があります (これについては、学習する必要がありますautoresizingmask)。そして、textFieldandを呼び出すときはkeyboard appears、フレームのサイズを縮小しscrollViewて、キーボードが表示されていてもスクロールする必要があります。
以下は、textFieldDidBeginEditing および textFieldDidEndEditing メソッドの私のコードです。
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[UIView beginAnimations: nil context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: 0.2];
scrollView.frame = CGRectMake(0,0,320,150);
[scrollView scrollRectToVisible:textField.frame animated:YES];
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self autoCalculateDownPayment];
[UIView beginAnimations: nil context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: 0.2];
scrollView.frame = CGRectMake(0,0,320,416);
[UIView commitAnimations];
}