我有一個帶有textview和按鈕的視圖,就像在任何典型的消息應用程序中一樣。當鍵盤出現時,文本視圖和按鈕也被向上推,但是內容被向上推離屏幕,在那裏我沒有看到它的頂端,但當我強制向下滾動時,我看到它爬下來,它向上彈當我放手的時候。我已經用快速草圖說明了我遇到的問題,第三個屏幕是所需的行爲。如何在軟件鍵盤向上推動時更改UIScrollView內容的高度
我在.xib文件中有這個視圖。我有一個觀點 - >滾動型 - >內容查看(其中有一個表,並TextView的和按鈕)
我註冊鍵盤的通知,這裏是爲顯示/隱藏方法的代碼
- (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];
}
不幸的是沒有爲我工作。文本視圖和按鈕隨滾動視圖一起移動。 – ioskaveen
請嘗試編輯答案 –
這也行不通。我想要做的是適合軟件鍵盤之間的導航欄下的視圖頂部的滾動視圖 – ioskaveen