【发布时间】:2020-07-29 05:17:58
【问题描述】:
我在顶部有一个 UITextView,在中间有一个 UITextView,在底部有一个 UITextView。 如果使用底部的 UITextView 或中心的 UITextView,我想在键盘出现时向上移动视图,但使用顶部的 UITextView 时视图不应该移动。
我该如何进行这项工作?
func showLoginKeyBoard()
{
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
}
@objc func keyboardWillShow(notification: NSNotification)
{
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
{
if self.view.frame.origin.y == 0
{
self.view.frame.origin.y -= keyboardSize.height
}
}
}
func textViewDidBeginEditing(_ textView: UITextView)
{
if textView == centreTextView
{
showLoginKeyBoard()
}
if textView == bottomTextView
{
showLoginKeyBoard()
}
}
目前,当任何 UITextViews 成为FirstResponder 时,视图会向上移动,这意味着当使用顶部 UITextView 时,它是不可见的。
如何确保顶部的 UITextView 不会向上移动视图?
【问题讨论】:
标签: ios swift xcode uiview uitextview