iOS 6 を使用UIViewController
していUIScrollView
ます。これScrollView
はログイン画面です。つまり、ログインするためのラベル、テキスト フィールド、およびボタンです。
キーボードが飛び出したときに適切なフィールドにスクロールするために、Apple 開発者ドキュメントの次のコードを使用します。
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect bkgndRect = self.activeField.superview.frame;
bkgndRect.size.height += kbSize.height;
[self.activeField.superview setFrame:bkgndRect];
[self.scrollView setContentOffset:CGPointMake(0.0, self.activeField.frame.origin.y-kbSize.height) animated:YES];
}
- (void)resetUIEdgeInsets
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
self.scrollView.contentInset = contentInsets;
self.scrollView.scrollIndicatorInsets = contentInsets;
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
[self resetUIEdgeInsets];
}
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self resetUIEdgeInsets];
[self registerForKeyboardNotifications];
}
それは正常に動作します。この問題は、モーダルで別のビュー コントローラーにセグエして、ここに戻ると発生します。スクロール位置が(断続的に)完全にスペースから外れていることがあります。
私はここで何か間違ったことをしていますか?ありがとう