我有以下功能,使鍵盤不覆蓋TextView,但鍵盤顯示不正確。相反,出現了一種沒有鍵盤按鍵的全黑「鍵盤」。鍵盤沒有正確顯示
func textViewDidBeginEditing(_ textView: UITextView) {
moveTextView(textView, moveDistance: -250, up: true)
}
func textViewDidEndEditing(_ textView: UITextView) {
moveTextView(textView, moveDistance: -250, up: false)
}
func textViewShouldReturn(_ textView: UITextView) -> Bool {
textView.resignFirstResponder()
return true
}
func moveTextView(_ textView: UITextView, moveDistance: Int, up: Bool) {
let moveDuration = 0.3
let movement: CGFloat = CGFloat(up ? moveDistance : -moveDistance)
UIView.beginAnimations("animateTextView", context: nil)
UIView.setAnimationBeginsFromCurrentState(true)
UIView.setAnimationDuration(moveDuration)
self.view.frame = self.view.frame.offsetBy(dx: 0, dy: movement)
UIView.commitAnimations()
}
難道有人對於爲什麼以及如何解決它有一個想法嗎?
謝謝你的時間。
嗨,謝謝你的評論。爲什麼'UITextFieldDelegate'而不是'UITextViewDelegate'? – alberzyzz
@alberzyzz是的。抱歉。如果你使用textView使用UITextViewDelegate –
鍵盤不顯示,並在視圖的頂部創建一個黑色的空間,增加每次我點擊textView – alberzyzz