CollectionView перемещается вверх, когда появляется клавиатура, затем возвращается в предыдущую позицию - PullRequest
0 голосов
/ 15 октября 2018

У меня есть collectionView и один textView внутри его ячейки.Когда в textView появляется клавиатура, но затем collectionView перемещается вверх, затем возвращается в предыдущую позициюКак это остановить?Как остановить перемещение collectionView при появлении клавиатуры?

Вот мой простой и очень простой код:

 class MainReadAssistantViewController: UICollectionViewController, 
UICollectionViewDelegateFlowLayout {
let wordOrPhraseCellId = "wordOrPhraseCellId"

override func viewDidLoad() {
    super.viewDidLoad()
    NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
   collectionView?.backgroundColor = UIColor.blue
collectionView?.register(WordOrPhraseCell.self, forCellWithReuseIdentifier: wordOrPhraseCellId)

    collectionView?.register(SentenceOrASuperLongPhrase.self, forCellWithReuseIdentifier: sentenceOrASuperLongPhraseCellId)
    collectionView?.isScrollEnabled = false

   // collectionView?.alwaysBounceVertical = true
     }

override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 1
}


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {


    return CGSize(width: view.frame.width, height: view.frame.height - 150)
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    var cell = collectionView.dequeueReusableCell(withReuseIdentifier: 
        return cell

        }
    }


    return cell
}

Это пример перемещения uicollectionView после появления клавиатуры.enter image description here

1 Ответ

0 голосов
/ 15 октября 2018

Это происходит для того, чтобы клавиатура не скрывала текстовые поля.Если вы хотите остановить это поведение (, я не рекомендую ) переопределить viewWillAppear(_:) без вызова super.viewWillAppear(animated).Например:

override func viewWillAppear(_ animated: Bool) {

}

Обратите внимание, что переопределение viewWillAppear(_:) без вызова метода super может привести к неопределенному поведению.

...