鍵盤狀態(tài)改變的時(shí)候,系統(tǒng)會(huì)發(fā)出一些特定的通知
UIKeyboardWillShowNotification//鍵盤即將顯示
UIKeyboardDidShowNotification//鍵盤顯示完畢
UIKeyboardWillHideNotification//鍵盤即將隱藏
UIKeyboardDidHideNotification//鍵盤隱藏完畢
UIKeyboardWillChangeFrameNotification//鍵盤的位置尺寸即將發(fā)生改變
UIKeyboardDidChangeFrameNotification//鍵盤的位置尺寸改變完畢
系統(tǒng)發(fā)出鍵盤通知時(shí),會(huì)附帶一下跟鍵盤有關(guān)的額外信息(字典),字典常見的key如下:
UIKeyboardFrameBeginUserInfoKey//鍵盤剛開始的frame
UIKeyboardFrameEndUserInfoKey//鍵盤最終的frame(動(dòng)畫執(zhí)行完畢后)
UIKeyboardAnimationDurationUserInfoKey//鍵盤動(dòng)畫的時(shí)間
UIKeyboardAnimationCurveUserInfoKey//鍵盤動(dòng)畫的執(zhí)行節(jié)奏(快慢)
UIKeyboardAnimationCurveUserInfoKey = 7; //動(dòng)畫執(zhí)行的節(jié)奏
UIKeyboardAnimationDurationUserInfoKey = "0.25";鍵盤彈出/隱藏的動(dòng)畫所需要的時(shí)間
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}”;//鍵盤的bounds
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 588}”;//鍵盤準(zhǔn)備彈出時(shí)的X,Y的中心坐標(biāo)
UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 372}”;//鍵盤彈出后的X,Y的中心坐標(biāo)
//鍵盤彈出剛開始的那一刻的frame
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 480}, {320, 216}}";
//彈出完畢的時(shí)候,鍵盤的frame
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 264}, {320, 216}}";
//鍵盤退出的frame
//鍵盤剛要退出那一刻的frame
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 264}, {320, 216}}";
//鍵盤退出完畢那一刻的frame
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 480}, {320, 216}}";
以下是swift:
extension NSNotification.Name {
public static let UIWindowDidBecomeVisible: NSNotification.Name
public static let UIWindowDidBecomeHidden: NSNotification.Name // nil
public static let UIWindowDidBecomeKey: NSNotification.Name // nil
public static let UIWindowDidResignKey: NSNotification.Name // nil
public static let UIKeyboardWillShow: NSNotification.Name
public static let UIKeyboardDidShow: NSNotification.Name
public static let UIKeyboardWillHide: NSNotification.Name
public static let UIKeyboardDidHide: NSNotification.Name
@available(iOS 5.0, *)
public static let UIKeyboardWillChangeFrame: NSNotification.Name
@available(iOS 5.0, *)
public static let UIKeyboardDidChangeFrame: NSNotification.Name