为什么我的 TableView 向上移动了?
我有一个在显示键盘时被调用的方法。它正在其他视图上工作。不知何故,TableView 向上移动了。
-(void) keyboardDidShow:(NSNotification *) notification {
// -- return if keyboard is still shown
MyManager *sharedManager = [MyManager sharedManager];
if ([sharedManager.keyboardIsShown isEqualToString:@"YES"]) return;
NSDictionary* info = [notification userInfo];
//---obtain the size of the keyboard---
NSValue *aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [self.view convertRect:[aValue CGRectValue] fromView:nil];
//---resize the scroll view (with keyboard)---
CGRect viewFrame = [scrollView frame];
viewFrame.size.height -= keyboardRect.size.height;
scrollView.frame = viewFrame;
//---scroll to the current text field---
CGRect textFieldRect = [currentTextField frame];
[scrollView scrollRectToVisible:textFieldRect animated:YES];
sharedManager.keyboardIsShown = @"YES";
}
I have a method that gets called when the keyboard is shown. It's working on other view. Somehow the TableView gets shifted up.
-(void) keyboardDidShow:(NSNotification *) notification {
// -- return if keyboard is still shown
MyManager *sharedManager = [MyManager sharedManager];
if ([sharedManager.keyboardIsShown isEqualToString:@"YES"]) return;
NSDictionary* info = [notification userInfo];
//---obtain the size of the keyboard---
NSValue *aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [self.view convertRect:[aValue CGRectValue] fromView:nil];
//---resize the scroll view (with keyboard)---
CGRect viewFrame = [scrollView frame];
viewFrame.size.height -= keyboardRect.size.height;
scrollView.frame = viewFrame;
//---scroll to the current text field---
CGRect textFieldRect = [currentTextField frame];
[scrollView scrollRectToVisible:textFieldRect animated:YES];
sharedManager.keyboardIsShown = @"YES";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置 myTableView.autoresizingMask = 0; 就可以了。
Setting
myTableView.autoresizingMask = 0;
did the trick.