2014-10-30 58 views
1

我有一个问题,我移动我的视图在键盘上出现的事件,而且我的视图底部有文本视图,这是一个聊天屏幕。 现在我的问题是,当键盘出现在iOS 8与快速键入我的撰写视图底部得到隐藏。所以我需要再次移动视图,如果出现类型,并在快速类型移开时重新定位。iOS8键盘快速键启动/关闭事件

在此先感谢。

回答

1

这个想法是检测键盘框架何时改变,然后相应地重新调整您的视图。看到这个解决方案QuickType Bar on the Keyboard

如果你已经有一个NSNotification检测你的键盘何时显示,那么你可以用这种方法来完成它。

-(void)keyboardWasShown:(NSNotification *)aNotification{ 

//this part detects the height of your keyboard, whether quicktype is open or not 
NSDictionary *keyboardInfo = [aNotification userInfo]; 
CGSize keyboardSize = [[keyboardInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; 
float keyboardHeight = keyboardSize.height; 

//animate message bar - this animation code works if autolayout is on 
[self.messageBarView layoutIfNeeded]; 
[UIView animateWithDuration:[aNotification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] animations:^{ 
    self.bottomConstraintMsgView.constant = keyboardHeight; 
    [self.messageBarView layoutIfNeeded]; 
}]; 

}

最重要的部分是当你宣布 “CGSize keyboardSize”。您必须像上面所做的那样使用UIKeyboardFrameEndUserInfoKey。这会在帧更改(快速键隐藏/显示)完成后显示帧大小。

+0

我已经尝试过相同的方法,但很难确定快捷类型是启用还是禁用,所以添加到您的答案是非常有帮助的(谢谢,我感谢您的回答:))我们必须跟踪前一帧和新帧。与下面的评论计算出的差异。附: – 2014-11-10 12:46:05

+0

NSDictionary * userInfo = [aNotification userInfo]; CGPoint begin = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue] .origin; CGPoint end = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue] .origin; if(begin.y> end.y)// QuickType被拉起 { iIsQuickTypeActive = YES; } 否则if(begin.y 2014-11-10 12:47:56