一般的なメッセージングアプリケーションのようなテキストビューとボタンが付いたビューがあります。キーボードが表示されると、テキストビューとボタンも上方向に押し込まれますが、コンテンツは上端が表示されない画面から上に押し出されますが、強制的に上にスクロールすると上に上がります私が離れるとき。私は素早いスケッチで問題を説明しました。第3の画面は望ましい動作です。ソフトウェアキーボードを押したときのUIScrollViewのコンテンツの高さを変更する方法
このビューは.xibファイルにあります。私は、ビューを持っている - 私は、キーボードの通知を登録し、ここで表示/非表示方法
- (void)registerForKeyboardNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardWasShown:(NSNotification *) aNotification {
NSDictionary *info = [aNotification userInfo];
CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
// the hardcoded 49 is the height of the uitabbar
UIEdgeInsets contentInsets = UIEdgeInsetsMake(-keyboardSize.height+49, 0.0, keyboardSize.height-49, 0.0);
self.scrollView.contentInset = contentInsets;
self.scrollView.scrollIndicatorInsets = contentInsets;
[self.view addGestureRecognizer:self.tapRecognizer];
}
- (void)keyboardWillBeHidden:(NSNotification *) aNotification {
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
self.scrollView.contentInset = contentInsets;
self.scrollView.scrollIndicatorInsets = contentInsets;
[self.view removeGestureRecognizer:self.tapRecognizer];
}
ためのコードです(テーブルとのTextViewとボタンがあります)> contentView
- > ScrollView
それは残念ながら私のために働かなかった。テキストビューとボタンはスクロールビューで移動しています。 – ioskaveen
編集した答えを試してください –
それはどちらも動作しません。私がしようとしているのは、ソフトウェアキーボードとナビゲーションバーのすぐ下にあるビューの一番上にあるスクロールビューを合わせることです – ioskaveen