Ios Whatsapp样式-键盘显示在工具栏下
我该怎么做whatsapp风格,当点击消息空间时,会将键盘从底部向上推,同时也会将工具栏向上推。然后,当取消时(即在后台单击),它将使用工具栏向下按键盘这是通过UIos Whatsapp样式-键盘显示在工具栏下,ios,keyboard,toolbar,whatsapp,Ios,Keyboard,Toolbar,Whatsapp,我该怎么做whatsapp风格,当点击消息空间时,会将键盘从底部向上推,同时也会将工具栏向上推。然后,当取消时(即在后台单击),它将使用工具栏向下按键盘这是通过UIKeyboardWillShowNotification、UIKeyboardDidShowNotification、UIKeyboardWillHideNotification和UIKeyboardDidenotification通知完成的。 然后在处理通知时,调整框架的高度: 例如: - (void) keyboardWillSh
IKeyboardWillShowNotification
、UIKeyboardDidShowNotification
、UIKeyboardWillHideNotification
和UIKeyboardDidenotification
通知完成的。
然后在处理通知时,调整框架的高度:
例如:
- (void) keyboardWillShow:(NSNotification *)aNotification{
NSDictionary* info = [aNotification userInfo];
NSTimeInterval duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
NSValue* aValue = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGFloat keyboardHeight = [aValue CGRectValue].size.height;
self.keyboardVissible = YES;
[UIView animateWithDuration:duration animations:^{
CGRect frame = self.contentView.frame;
frame.size.height -= keyboardHeight;
self.contentView.frame = frame;
}];
}
您需要注册以接收通知,您应该只在视图可见时收听键盘通知,如果您在viewDidLoad
中执行此操作,可能会发生奇怪的事情:
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void) viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
什么是fetchedResultsController?实际上我自己还不知道。键盘可视是什么?它只是一个额外的
BOOL
我用来跟踪键盘是否可见。