通知方法,获取键盘的左上角的point值

通知方法,获取键盘的左上角的point值,方便之后做其他的操作。

NotificationCenter.default.addObserver(self, selector: #selector(keyBoardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(keyBoardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)

//  当键盘弹出时调用的方法

func keyBoardWillShow(_ notification:Notification){

let dict = NSDictionary(dictionary: notification.userInfo!)

let keyBoardFrame = (dict[UIKeyboardFrameEndUserInfoKey]! asAnyObject).cgRectValue

let point = keyBoardFrame?.origin

self.frame = CGRect(x: (point?.x)!, y: (point?.y)! - mViewHeight, width: mWidth, height: mViewHeight)

}

func keyBoardWillHide(_ notification: Notification) {

self.frame = CGRect(x: 0, y: mHeight - mViewHeight, width: mWidth, height: mViewHeight)

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容