【发布时间】:2018-10-15 20:09:07
【问题描述】:
我在其单元格中有一个 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
}
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewlayout uikeyboard