0
我在Main.Storyboard中創建的UIViewController
內有TableView
。 初始化時Y位置爲0。 我的問題是,當鍵盤顯示時,TableView
的Y位置根本不會改變。 Y位置保持爲0.因此單元格隱藏在NavigationController後面。在鍵盤顯示時在UIViewController中設置Tableview的y位置
至今代碼:
-(void) keyboardWasShown:(NSNotification*)aNotification
{
if (kbIsShown == false) {
NSDictionary* info = [aNotification userInfo];
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
CGRect keyboardFrame;
[[info objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[[info objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&keyboardFrame];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];
NSLog(@"frame..%f..%f..%f..%f",self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
NSLog(@"keyboard..%f..%f..%f..%f",keyboardFrame.origin.x, keyboardFrame.origin.y, keyboardFrame.size.width, keyboardFrame.size.height);
[self.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y - keyboardFrame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[chatTable setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + keyboardFrame.size.height + TABBAR_HEIGHT, self.view.frame.size.width, self.view.frame.size.height-keyboardFrame.size.height)];
[UIView commitAnimations];
NSLog(@"Visar sig");
kbIsShown = true;
}
}
的[chatTable setFrame:]
沒有做任何事情。Y位置保持爲0.如何更改Tableview的Y位置以便我的內容可見?
注意:[self.view setFrame...]
確實會改變視圖的Y位置。但chatTable
停留在0
http://stackoverflow.com/questions/13845426/generic-uitableview-keyboard-resizing-algorithm – rakeshbs 2015-01-04 13:44:37
Thanks @rakeshbs!我設法使它工作!我做了一些小的改變! – Dridia 2015-01-04 15:23:22
不客氣。 – rakeshbs 2015-01-04 15:24:01