美文网首页iOS-swift
2.IOS(swift)-scrollView ·Keyboar

2.IOS(swift)-scrollView ·Keyboar

作者: 俊瑶先森 | 来源:发表于2015-03-05 12:35 被阅读701次
    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)
    ```
    ```
    deinit{
             NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    ```
    
    ```
    func keyboardWillShow(notification: NSNotification) {
            adjustInsetForKeyboardShow(true, notification: notification)
        }
    func keyboardWillHide(notification: NSNotification) {
            adjustInsetForKeyboardShow(false, notification: notification)
        }
    func adjustInsetForKeyboardShow(show:Bool,notification:NSNotification){
            let userInfo = notification.userInfo ?? [:]
            let keyboardFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as NSValue).CGRectValue()
            let adjustmentHeight = (CGRectGetHeight(keyboardFrame)) * (show ? 1:-1)
            fgScrollview.contentInset.bottom += adjustmentHeight
            fgScrollview.scrollIndicatorInsets.bottom += adjustmentHeight    
    }
    
    ```

    相关文章

      网友评论

        本文标题:2.IOS(swift)-scrollView ·Keyboar

        本文链接:https://www.haomeiwen.com/subject/jwwmxttx.html