我正在 ios 中开发一个聊天应用程序,我有自定义的 tableview 和 UIView,底部有一些 textfield ane 按钮。当 Textfield 被激活时,我想用键盘移动 UIView 和 Tableview。我有这个观察者:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
然后是keyboardWasShown方法:
- (void)keyboardWasShown:(NSNotification*)aNotification{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
NSNumber *number = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
double duration = [number doubleValue];
[UIView animateWithDuration:duration animations:^{
CGRect frame = textInputView.frame;
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
self.kHeight = kbSize.height;
}
else if(UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
self.kHeight = kbSize.width;
}
NSLog(@"keyboard up y =%f",self.kHeight);
frame.origin.y -= self.kHeight;
textInputView.frame = frame;
frame = bubbleTable.frame;
frame.size.height -= self.kHeight;
bubbleTable.frame = frame;
}];
它正在工作,但您注意到 UIview 不像在 facebook 或 viber 应用程序中那样顺利移动。所以我想问一下这个的常用方法是什么。十分感谢!