修复键盘弹起时遮挡底部文本的问题
This commit is contained in:
@@ -28,6 +28,11 @@ class FormatLogViewController: UIViewController {
|
|||||||
navigationItem.largeTitleDisplayMode = .never
|
navigationItem.largeTitleDisplayMode = .never
|
||||||
view.backgroundColor = .systemGroupedBackground
|
view.backgroundColor = .systemGroupedBackground
|
||||||
setupUI()
|
setupUI()
|
||||||
|
setupKeyboardObservers()
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
NotificationCenter.default.removeObserver(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setupUI() {
|
private func setupUI() {
|
||||||
@@ -77,6 +82,34 @@ class FormatLogViewController: UIViewController {
|
|||||||
textView.resignFirstResponder()
|
textView.resignFirstResponder()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func setupKeyboardObservers() {
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func keyboardWillShow(_ notification: Notification) {
|
||||||
|
guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
|
||||||
|
let keyboardFrameInView = view.convert(keyboardFrame, from: nil)
|
||||||
|
let intersection = keyboardFrameInView.intersection(view.bounds)
|
||||||
|
let keyboardHeight = intersection.height
|
||||||
|
|
||||||
|
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0.25
|
||||||
|
|
||||||
|
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState) {
|
||||||
|
self.textView.contentInset.bottom = keyboardHeight
|
||||||
|
self.textView.verticalScrollIndicatorInsets.bottom = keyboardHeight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func keyboardWillHide(_ notification: Notification) {
|
||||||
|
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0.25
|
||||||
|
|
||||||
|
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState) {
|
||||||
|
self.textView.contentInset.bottom = 0
|
||||||
|
self.textView.verticalScrollIndicatorInsets.bottom = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@objc private func didTapFormatButton() {
|
@objc private func didTapFormatButton() {
|
||||||
guard !trimmedText().isEmpty else {
|
guard !trimmedText().isEmpty else {
|
||||||
showEmptyAlert()
|
showEmptyAlert()
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ class FormatNoteViewController: UIViewController {
|
|||||||
navigationItem.largeTitleDisplayMode = .never
|
navigationItem.largeTitleDisplayMode = .never
|
||||||
view.backgroundColor = .systemGroupedBackground
|
view.backgroundColor = .systemGroupedBackground
|
||||||
setupUI()
|
setupUI()
|
||||||
|
setupKeyboardObservers()
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
NotificationCenter.default.removeObserver(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setupUI() {
|
private func setupUI() {
|
||||||
@@ -101,6 +106,34 @@ class FormatNoteViewController: UIViewController {
|
|||||||
textView.resignFirstResponder()
|
textView.resignFirstResponder()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func setupKeyboardObservers() {
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func keyboardWillShow(_ notification: Notification) {
|
||||||
|
guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
|
||||||
|
let keyboardFrameInView = view.convert(keyboardFrame, from: nil)
|
||||||
|
let intersection = keyboardFrameInView.intersection(view.bounds)
|
||||||
|
let keyboardHeight = intersection.height
|
||||||
|
|
||||||
|
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0.25
|
||||||
|
|
||||||
|
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState) {
|
||||||
|
self.textView.contentInset.bottom = keyboardHeight
|
||||||
|
self.textView.verticalScrollIndicatorInsets.bottom = keyboardHeight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func keyboardWillHide(_ notification: Notification) {
|
||||||
|
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0.25
|
||||||
|
|
||||||
|
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState) {
|
||||||
|
self.textView.contentInset.bottom = 0
|
||||||
|
self.textView.verticalScrollIndicatorInsets.bottom = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@objc private func didTapPasteButton() {
|
@objc private func didTapPasteButton() {
|
||||||
if let string = UIPasteboard.general.string {
|
if let string = UIPasteboard.general.string {
|
||||||
textView.text = string
|
textView.text = string
|
||||||
|
|||||||
Reference in New Issue
Block a user