键盘状态改变的时候,系统会发出一些特定的通知
UIKeyboardWillShowNotification//键盘即将显示
UIKeyboardDidShowNotification//键盘显示完毕
UIKeyboardWillHideNotification//键盘即将隐藏
UIKeyboardDidHideNotification//键盘隐藏完毕
UIKeyboardWillChangeFrameNotification//键盘的位置尺寸即将发生改变
UIKeyboardDidChangeFrameNotification//键盘的位置尺寸改变完毕
系统发出键盘通知时,会附带一下跟键盘有关的额外信息(字典),字典常见的key如下:
UIKeyboardFrameBeginUserInfoKey//键盘刚开始的frame
UIKeyboardFrameEndUserInfoKey//键盘最终的frame(动画执行完毕后)
UIKeyboardAnimationDurationUserInfoKey//键盘动画的时间
UIKeyboardAnimationCurveUserInfoKey//键盘动画的执行节奏(快慢)
UIKeyboardAnimationCurveUserInfoKey = 7; //动画执行的节奏
UIKeyboardAnimationDurationUserInfoKey = "0.25";键盘弹出/隐藏的动画所需要的时间
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}”;//键盘的bounds
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 588}”;//键盘准备弹出时的X,Y的中心坐标
UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 372}”;//键盘弹出后的X,Y的中心坐标
//键盘弹出刚开始的那一刻的frame
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 480}, {320, 216}}";
//弹出完毕的时候,键盘的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
网友评论