キーボードを閉じるまで完全に機能するスクロールビューがあります。その後、スクロールしますが、完全には下に行きません... 少し戸惑います。
viewDidLoad でフレームを保存して、後でリセットできるようにします
frame = self.scrollView.frame;
NSLog(@"Height beginning: %f",self.scrollView.frame.size.height);
offset = self.scrollView.contentOffset;
デバッグのために、スクロールビューの高さ 629 を確認しました
私のキーボードのDidHideメソッドで、古いフレームを元に戻しました
self.scrollView.frame = frame;
NSLog(@"Height end: %f",self.scrollView.frame.size.height);
// Reset the scrollview to previous location
self.scrollView.contentOffset = offset;
デバッグ出力も 629 です。これは、スクロールビューの高さが古い値に設定されていることを意味します。スクロールはしますが、離すと最初に戻ってしまいます...
編集:
高さとして 480 を使用すると、iphone 4 のために画面全体がいっぱいになりません。
いくつかのコード
-(void) keyboardDidShow: (NSNotification *)notif
{
NSLog(@"Keyboard is visible");
// If keyboard is visible, return
if (keyboardVisible) {
NSLog(@"Keyboard is already visible. Ignore notification.");
return;
}
// Get the size of the keyboard.
CGRect keyboardEndFrame;
[[notif.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
// Resize the scroll view to make room for the keyboard
CGRect viewFrame = frame;
viewFrame.size.height = 200;
//viewFrame.size.height -= keyboardEndFrame.size.height;
self.scrollView.frame = viewFrame;
offset = self.scrollView.contentOffset;
CGRect textFieldRect;
if(!activeField)
textFieldRect = comment.frame;
else
textFieldRect = activeField.frame;
textFieldRect.origin.y += 10;
[self.scrollView scrollRectToVisible:textFieldRect animated:YES];
// Keyboard is now visible
keyboardVisible = YES;
}
-(void) keyboardDidHide: (NSNotification *)notif
{
// Is the keyboard already shown
if (!keyboardVisible) {
NSLog(@"Keyboard is already hidden. Ignore notification.");
return;
}
//viewFrame.size.height -= keyboardEndFrame.size.height;
self.scrollView.frame = frame;
[self.scrollView setContentSize:CGSizeMake(320, 700)];
// Reset the scrollview to previous location
self.scrollView.contentOffset = offset;
// Keyboard is no longer visible
keyboardVisible = NO;
}