swift3 键盘通知事件

swift3 键盘通知事件,第1张

概述class MyViewController: UIViewController {// This constraint ties an element at zero points from the bottom layout guide@IBOutlet var keyboardHeightLayoutConstraint: NSLayoutConstraint?override f
class MyVIEwController: UIVIEwController {// This constraint tIEs an element at zero points from the bottom layout guIDe@IBOutlet var keyboardHeightLayoutConstraint: NSLayoutConstraint?overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    // Note that SO highlighting makes the new selector Syntax (#selector()) look    // like a comment but it isn't one    NotificationCenter.default.addobserver(self,selector: #selector(self.keyboardNotification(notification:)),name: NSNotification.name.UIKeyboarDWillChangeFrame,object: nil)}deinit {    NotificationCenter.default.removeObserver(self)}@objc func keyboardNotification(notification: NSNotification) {    if let userInfo = notification.userInfo {        let endFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue        let duration:TimeInterval = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0        let animationCurveRawNSN = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber        let animationCurveRaw = animationCurveRawNSN?.uintValue ?? UIVIEwAnimationoptions.curveEaseInOut.rawValue        let animationCurve:UIVIEwAnimationoptions = UIVIEwAnimationoptions(rawValue: animationCurveRaw)        if (endFrame?.origin.y)! >= UIScreen.main.bounds.size.height {            self.keyboardHeightLayoutConstraint?.constant = 0.0        } else {            self.keyboardHeightLayoutConstraint?.constant = endFrame?.size.height ?? 0.0        }        UIVIEw.animate(withDuration: duration,delay: TimeInterval(0),options: animationCurve,animations: { self.vIEw.layoutIfNeeded() },completion: nil)    }}
总结

以上是内存溢出为你收集整理的swift3 键盘通知事件全部内容,希望文章能够帮你解决swift3 键盘通知事件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1090191.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存