Skip to content

Commit

Permalink
#297: ShareViewController 텍스트뷰 클릭해서 키보드 올라오고 내려갈때 뷰 높이 조절
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph704 committed Aug 14, 2024
1 parent 6f2c6e1 commit 98fa46d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions StreetDrop/ShareExtension/View/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ final class ShareViewController: UIViewController {
bindAction()
bindViewModel()
configureUI()
registerKeyboardNotification()

// 공유된 데이터 가져오기
guard let extensionItem = extensionContext?.inputItems.first as? NSExtensionItem else { return }
Expand Down Expand Up @@ -477,3 +478,41 @@ extension ShareViewController: UITextViewDelegate {
return true
}
}

// MARK: - KeyBoard
private extension ShareViewController {
func registerKeyboardNotification() {
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 func keyboardWillShow(_ notification: Notification) {
UIView.animate(withDuration: 0.3) { [weak self] in
guard let self = self else { return }
containerView.snp.updateConstraints { [weak self] in
guard let self = self else { return }

$0.height.equalTo(view.bounds.height)
}
view.layoutIfNeeded()
}
}

@objc func keyboardWillHide() {
UIView.animate(withDuration: 0.3) { [weak self] in
self?.containerView.snp.updateConstraints {
let screenHeight = UIScreen.main.bounds.height
$0.height.equalTo(596)
}
self?.view.layoutIfNeeded()
}
}
}

0 comments on commit 98fa46d

Please sign in to comment.