首先注册通知如下:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name:UIKeyboardWillChangeFrameNotification, object:nil)
func keyboardWillShow(noti:NSNotification){
var userInfo :NSDictionary = noti.userInfo!
var duration : NSValue = userInfo["UIKeyboardAnimationDurationUserInfoKey"]asNSValue
var animationDuration : NSTimeInterval ! = 0
duration.getValue(&animationDuration)
var keyFrame : NSValue = userInfo[ "UIKeyboardFrameEndUserInfoKey" ] as NSValue
var krect = keyFrame.CGRectValue()
}打印内容如下:
注明:这是iPad横向的时候哦。
iOS7.1:键盘响应,弹起
{
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = "0.25";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {1024, 406}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {512, 971}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {512, 565}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{-406, 0}, {406, 1024}}";
UIKeyboardFrameChangedByUserInteraction = 0;
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 0}, {406, 1024}}";
}
键盘响应,收回resignFirstResponder
UIKeyboardWillChangeFrameNotification; userInfo = {
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = "0.25";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {1024, 406}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {512, 565}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {512, 971}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 0}, {406, 1024}}";
UIKeyboardFrameChangedByUserInteraction = 0;
UIKeyboardFrameEndUserInfoKey = "NSRect: {{-406, 0}, {406, 1024}}";
}
iOS8:键盘响应,弹起
{
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = "0.25";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {1024, 406}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {512, 971}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {512, 565}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 768}, {1024, 406}}";
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 362}, {1024, 406}}";
}
{
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = "0.25";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {1024, 406}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {512, 565}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {512, 971}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 362}, {1024, 406}}";
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 768}, {1024, 406}}";
}
原文:http://blog.csdn.net/yanyanforest/article/details/44803503
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!