Skip to content

Commit

Permalink
[Feat] sopt-makers#12 - 키보드 등장 시 화면 자동 스크롤 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Nov 28, 2022
1 parent 097df5d commit c243e53
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public class SignUpVC: UIViewController {
self.setUI()
self.setLayout()
self.setTapGesture()
self.setKeyboardNotification()
}

}

// MARK: - Methods
Expand Down Expand Up @@ -149,4 +149,39 @@ extension SignUpVC {
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
}

private func setKeyboardNotification() {
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 userInfo = notification.userInfo,
let keyboardFrame = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else {
return
}

let contentInset = UIEdgeInsets(
top: 0.0,
left: 0.0,
bottom: keyboardFrame.size.height,
right: 0.0)
scrollView.contentInset = contentInset
scrollView.scrollIndicatorInsets = contentInset
}

@objc private func keyboardWillHide() {
let contentInset = UIEdgeInsets.zero
scrollView.contentInset = contentInset
scrollView.scrollIndicatorInsets = contentInset
}
}

0 comments on commit c243e53

Please sign in to comment.