Swift3.0 键盘高度监听获取
生活随笔
收集整理的這篇文章主要介紹了
Swift3.0 键盘高度监听获取
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
方法:通過通知監聽鍵盤的動態
1.鍵盤的動態有四種:
public static let UIKeyboardWillShow: NSNotification.Namepublic static let UIKeyboardDidShow: NSNotification.Namepublic static let UIKeyboardWillHide: NSNotification.Namepublic static let UIKeyboardDidHide: NSNotification.Name2.下面監聽下彈出之前,和回收之前的事件
//鍵盤彈起@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).cgRectValuelet height = keyRect?.size.heightprint(height!)}//鍵盤收起@objc private func willHide(nottification:NSNotification){}
?
轉載于:https://www.cnblogs.com/xingsmile/p/6283052.html
總結
以上是生活随笔為你收集整理的Swift3.0 键盘高度监听获取的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Storm概念学习系列之Topology
- 下一篇: day2 字典常用的方法