@@ -63,6 +63,11 @@ final class WithdrawViewController: BaseViewController<WithdrawViewModel> {
6363 }
6464 }
6565
66+ override func viewWillDisappear( _ animated: Bool ) {
67+ super. viewWillDisappear ( animated)
68+ removeKeyboardNotification ( )
69+ }
70+
6671 private func updateConstraint( ) {
6772 let height = view. bounds. height
6873 if height <= 667 {
@@ -151,6 +156,8 @@ final class WithdrawViewController: BaseViewController<WithdrawViewModel> {
151156 let tapGesture = UITapGestureRecognizer ( target: self , action: #selector( dismissKeyboard) )
152157 tapGesture. cancelsTouchesInView = false
153158 view. addGestureRecognizer ( tapGesture)
159+
160+ configureKeyboardNotification ( )
154161 }
155162
156163 override func configureLayout( ) {
@@ -301,14 +308,73 @@ final class WithdrawViewController: BaseViewController<WithdrawViewModel> {
301308 }
302309 }
303310
311+ private func configureKeyboardNotification( ) {
312+ NotificationCenter . default. addObserver (
313+ self ,
314+ selector: #selector( keyboardWillAppear) ,
315+ name: UIResponder . keyboardWillShowNotification,
316+ object: nil )
317+
318+ NotificationCenter . default. addObserver (
319+ self ,
320+ selector: #selector( keyboardWillDisappear) ,
321+ name: UIResponder . keyboardWillHideNotification,
322+ object: nil )
323+ }
324+
325+ private func removeKeyboardNotification( ) {
326+ NotificationCenter . default. removeObserver (
327+ self ,
328+ name: UIResponder . keyboardWillShowNotification,
329+ object: nil )
330+
331+ NotificationCenter . default. removeObserver (
332+ self ,
333+ name: UIResponder . keyboardWillHideNotification,
334+ object: nil )
335+ }
336+
304337 @objc private func dismissKeyboard( ) {
305338 view. endEditing ( true )
306339 }
340+
341+ @objc private func keyboardWillAppear( _ sender: Notification ) {
342+ guard
343+ let keyboardFrame = sender. userInfo ? [ UIResponder . keyboardFrameEndUserInfoKey] as? CGRect ,
344+ let duration = sender. userInfo ? [ UIResponder . keyboardAnimationDurationUserInfoKey] as? Double
345+ else { return }
346+
347+ let keyboardHeight = keyboardFrame. height
348+ let buttonFrame = withdrawButton. convert ( withdrawButton. bounds, to: view)
349+ let buttonBottom = buttonFrame. maxY
350+ let visibleHeight = view. frame. height - keyboardHeight
351+
352+ if buttonBottom > visibleHeight {
353+ let offset = buttonBottom - visibleHeight + 50
354+
355+ UIView . animate ( withDuration: duration) {
356+ self . view. frame. origin. y = - offset
357+ }
358+ }
359+ }
360+
361+ @objc private func keyboardWillDisappear( _ sender: Notification ) {
362+ guard let duration = sender. userInfo ? [ UIResponder . keyboardAnimationDurationUserInfoKey] as? Double
363+ else { return }
364+
365+ UIView . animate ( withDuration: duration) {
366+ self . view. frame. origin. y = 0
367+ }
368+ }
307369}
308370
309371extension WithdrawViewController : UITextViewDelegate {
310372 func textViewDidBeginEditing( _ textView: UITextView ) {
311373 viewModel. action ( input: . choiceWithdrawReason( reason: nil ) )
374+
375+ if !textView. text. isEmpty {
376+ viewModel. action ( input: . inputWithdrawReason( reason: textView. text) )
377+ }
312378 }
313379
314380 func textViewDidChange( _ textView: UITextView ) {
0 commit comments