我正在使用聊天应用。当我的键盘出现时,我想根据键盘框架调整表格视图和文字视图的大小。
问题是当我的键盘出现时,我的表格视图会自动调整大小并重新定位。
我的代码是..
-(void)KeyboardWillShow:(NSNotification *)keyboardInfo
{
@try {
NSDictionary *userInfo = keyboardInfo.userInfo;
// Get keyboard size.
NSValue *endFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey];
CGRect keyboardEndFrame = [self.view convertRect:endFrameValue.CGRectValue fromView:nil];
// Get keyboard animation.
NSNumber *durationValue = userInfo[UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval animationDuration = durationValue.doubleValue;
NSNumber *curveValue = userInfo[UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve animationCurve = curveValue.intValue;
[UIView animateWithDuration:animationDuration delay:0.0 options:(animationCurve<<16) animations:^{
[self.messageView setFrame:CGRectMake(self.messageView.frame.origin.x, self.view.frame.size.height-keyboardEndFrame.size.height-self.messageView.frame.size.height, self.messageView.frame.size.width, self.messageView.frame.size.height)];
[self.tableView setFrame:CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.view.frame.size.height-keyboardEndFrame.size.height-self.messageView.frame.size.height-self.tableView.frame.origin.y)];
} completion:nil];
}
@catch (NSException *exception) {
NSLog(@"Error in func:%s, line:%d with reason:%@",__func__,__LINE__,exception.reason);
}
}
] 2
答案 0 :(得分:0)
获取tableview底部约束的出口并以编程方式将其更改为
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>userName</value>
<description>user name for connecting to mysql server</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>password</value>
<description>password for connecting to mysql server</description>
</property>
答案 1 :(得分:0)
你冷使用表格插图,修改tableView内容的底部插图:
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardEndFrame.size.height + self.messageView.frame.size.height, 0);