KeyBoard 在iOS7和iOS8上通知的区别

18 篇文章 0 订阅

要想在界面加入qq类似的聊天键盘

首先注册通知如下:

            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"]asNSValue

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

}

//////////////////

注明:这是iPad竖屏的时候哦。

iOS7.1:键盘响应,弹起

UIKeyboardWillChangeFrameNotification; userInfo = {

    UIKeyboardAnimationCurveUserInfoKey = 7;

    UIKeyboardAnimationDurationUserInfoKey = "0.25";

    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {768, 318}}";

    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {384, 1183}";

    UIKeyboardCenterEndUserInfoKey = "NSPoint: {384, 865}";

    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 706}, {768, 318}}";

    UIKeyboardFrameChangedByUserInteraction = 0;

    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 706}, {768, 318}}";

}}

键盘响应,收回resignFirstResponder

UIKeyboardWillChangeFrameNotification; userInfo = {

    UIKeyboardAnimationCurveUserInfoKey = 7;

    UIKeyboardAnimationDurationUserInfoKey = "0.25";

    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {768, 318}}";

    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {384, 865}";

    UIKeyboardCenterEndUserInfoKey = "NSPoint: {384, 1183}";

    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 706}, {768, 318}}";

    UIKeyboardFrameChangedByUserInteraction = 0;

    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 1024}, {768, 318}}";

}}


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

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值