在遇到有輸入的情況下。由於現在鍵盤的高度是動態變化的。中文輸入與英文輸入時高度不同。所以輸入框的位置也要做出相應的變化
添加監聽事件:
//增加監聽,當鍵盤出現或改變時收出消息
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification//這個是帶系統動畫的
//UIKeyboardDidShowNotification 鍵盤出來後再出現,不帶動畫
object:nil];
//增加監聽,當鍵退出時收出消息
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
//當鍵盤出現或改變時調用
- (void)keyboardWillShow:(NSNotification *)aNotification
{
//獲取鍵盤的高度
NSDictionary *userInfo = [aNotification userInfo];
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValue CGRectValue];
int height = keyboardRect.size.height;
}
//當鍵退出時調用
- (void)keyboardWillHide:(NSNotification *)aNotification
{
}