2014-10-30 53 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