KeyBoard 在iOS7和iOS8上通知的区别

首先注册通知如下:

            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}}";

}

键盘响应,收回resignFirstResponder

{

    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}}";

}


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。