Swift3.0 键盘高度监听获取

方法:通过通知监听键盘的动态

1.键盘的动态有四种:

 public static let UIKeyboardWillShow: NSNotification.Name

    public static let UIKeyboardDidShow: NSNotification.Name

    public static let UIKeyboardWillHide: NSNotification.Name

    public static let UIKeyboardDidHide: NSNotification.Name

2.下面监听下弹出之前,和回收之前的事件

//键盘弹起
    @objc private func willShow(nottification:NSNotification){
        
        let info:NSDictionary = nottification.userInfo as NSDictionary!
//        print(info)
       //通过输出看到下面的信息
    
         /*
Optional([AnyHashable("UIKeyboardCenterBeginUserInfoKey"): NSPoint: {207, 849},
            
AnyHashable("UIKeyboardIsLocalUserInfoKey"): 1,
           
AnyHashable("UIKeyboardCenterEndUserInfoKey"): NSPoint: {207, 623},
            
AnyHashable("UIKeyboardBoundsUserInfoKey"): NSRect: {{0, 0}, {414, 226}},
            
AnyHashable("UIKeyboardFrameEndUserInfoKey"): NSRect: {{0, 510}, {414, 226}},
                     
AnyHashable("UIKeyboardAnimationCurveUserInfoKey"): 7,
           
AnyHashable("UIKeyboardFrameBeginUserInfoKey"): NSRect: {{0, 736}, {414, 226}},
            
AnyHashable("UIKeyboardAnimationDurationUserInfoKey"): 0.25])
*/ //取出键盘的高度 let keyValue = info.object(forKey: "UIKeyboardFrameEndUserInfoKey") let keyRect = (keyValue as AnyObject).cgRectValue let height = keyRect?.size.height print(height!) } //键盘收起 @objc private func willHide(nottification:NSNotification){ }

 

转载于:https://www.cnblogs.com/xingsmile/p/6283052.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值