5

IQKeyboardManagerキーボードで入力した後、テキストフィールドが上がるように使用しています。

テキスト フィールドをクリックしても、特定のビューにスクロールしたくありません。以下はデザインのスクリーンショットです。「ヘッダー」を一番上に残したい。

ビューのインスペクタ レイアウト

彼らのドキュメンテーションから、ナビゲーションバーを一番上に保つ方法があります。

4

3 に答える 3

4

ViewController の IQKeyboardManager を無効にします。

そのために、

IQKeyboardManager.sharedManager().disableInViewControllerClass(ViewController.self)

そして、そのviewControllerに次のコードを書きます。キーボードの高さに応じてビューを上に移動します

override func viewDidLoad() {
        super.viewDidLoad()

        NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)

}

func keyboardWillShow(notification: NSNotification) {

        if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
            if self.view.frame.origin.y == 0 {
                self.view.frame.origin.y -= keyboardSize.height
            }
        }
}

func keyboardWillHide(notification: NSNotification) {
        if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
            if self.view.frame.origin.y != 0 {
                self.view.frame.origin.y += keyboardSize.height
            }
        }
}

「 HEADER」ビューをTOPに残しておきたい場合は、

このようにしてください:

**

YourViewController.view -> [headerView][contentView]

**

textfieldを [ contentView ] に配置し、上記のコードの Self.view の代わりに [contentView].y を変更します。

于 2016-10-19T08:16:40.770 に答える
4

を無効にIQKeyboardManagerしますviewController

override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        IQKeyboardManager.sharedManager().enable = false

        NotificationCenter.default.addObserver(self, selector: #selector(Login.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(Login.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}

ハンドル キーボード:

func keyboardWillShow(notification: NSNotification) {

        if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
            if self.view.frame.origin.y == 0{
            self.table_view.frame.origin.y -= keyboardSize.height
            }
        }
    }

func keyboardWillHide(notification: NSNotification) {
        if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
            if self.view.frame.origin.y != 0{
            self.table_view.frame.origin.y += keyboardSize.height
            }
        }
    }

オブザーバーを削除します。

override func viewWillDisappear(animated: Bool) {
        IQKeyboardManager.sharedManager().enable = true
        NSNotificationCenter.defaultCenter().removeObserver(self)    
    }
于 2016-10-19T13:05:38.797 に答える