ios处理键盘的大小
iOS的键盘有几个通知
UIKeyboardWillShowNotification UIKeyboardDidShowNotification UIKeyboardWillHideNotification UIKeyboardDidHideNotification
每一个通知的具体内容是什么呢
UIKeyboardAnimationCurveUserInfoKey = 7; UIKeyboardAnimationDurationUserInfoKey = "0.25"; UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {375, 258}}"; UIKeyboardCenterBeginUserInfoKey = "NSPoint: {187.5, 796}"; UIKeyboardCenterEndUserInfoKey = "NSPoint: {187.5, 538}"; UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 667}, {375, 258}}"; UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 409}, {375, 258}}"; UIKeyboardIsLocalUserInfoKey = 1;
键盘大小的转换
通知里的大小是屏幕坐标系中的大小和位置,没有考虑旋转。因此需要一次转化。let rect = self.view.convertRect(keyboardrect!, fromView: nil)
为啥不能假设键盘有一个固定的大小
- 不同输入法的键盘大小可能不同 iOS9 的中文输入法比英文的大那么一点点
- 不同版本的键盘大小也不同
- 屏幕旋转时,屏幕的大小也不同