【发布时间】:2015-01-04 13:17:27
【问题描述】:
我在 Main.Storyboard 中创建的 UIViewController 中有一个 TableView。
初始化时 Y 位置为 0。
我的问题是,当键盘显示时,TableView 的 Y 位置根本没有改变。 Y 位置保持在 0。因此单元格隐藏在 NavigationController 后面。
到目前为止的代码:
-(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:] 不执行任何操作。 TableViews (chatTable) Y 位置保持在 0。如何更改 Tableview 的 Y 位置以便我的内容可见?
注意:[self.view setFrame...] 确实改变了视图的 Y 位置。但是chatTable 保持在 0。
【问题讨论】:
-
谢谢@rakeshbs!我设法使它工作!我做了一些小改动!
标签: ios objective-c uitableview uiview uiviewcontroller