fix: make button display on the top of the keyboard

This commit is contained in:
CMK 2021-02-22 16:37:13 +08:00
parent abf2e673e1
commit 832432f42f
1 changed files with 29 additions and 18 deletions

View File

@ -329,9 +329,18 @@ extension MastodonRegisterViewController {
self.scrollView.verticalScrollIndicatorInsets.bottom = 0.0 self.scrollView.verticalScrollIndicatorInsets.bottom = 0.0
return return
} }
self.scrollView.contentInset.bottom = padding + 16 self.scrollView.contentInset.bottom = padding + 16
self.scrollView.verticalScrollIndicatorInsets.bottom = padding + 16 self.scrollView.verticalScrollIndicatorInsets.bottom = padding + 16
if self.passwordTextField.isFirstResponder {
let contentFrame = self.scrollView.convert(self.signUpButton.frame, to: nil)
let labelPadding = contentFrame.maxY - endFrame.minY
let contentOffsetY = self.scrollView.contentOffset.y
DispatchQueue.main.async {
self.scrollView.setContentOffset(CGPoint(x: 0, y: contentOffsetY + labelPadding + 16.0), animated: true)
}
}
}) })
.store(in: &disposeBag) .store(in: &disposeBag)
@ -425,23 +434,25 @@ extension MastodonRegisterViewController {
} }
extension MastodonRegisterViewController: UITextFieldDelegate { extension MastodonRegisterViewController: UITextFieldDelegate {
func textFieldDidBeginEditing(_ textField: UITextField) {
// align to password label when overlap // FIXME: keyboard listener trigger when switch between text fields. Maybe could remove it
if textField === passwordTextField, // func textFieldDidBeginEditing(_ textField: UITextField) {
KeyboardResponderService.shared.isShow.value, // // align to password label when overlap
KeyboardResponderService.shared.state.value == .dock // if textField === passwordTextField,
{ // KeyboardResponderService.shared.isShow.value,
let endFrame = KeyboardResponderService.shared.willEndFrame.value // KeyboardResponderService.shared.state.value == .dock
let contentFrame = scrollView.convert(passwordCheckLabel.frame, to: nil) // {
let padding = contentFrame.maxY - endFrame.minY // let endFrame = KeyboardResponderService.shared.willEndFrame.value
if padding > 0 { // let contentFrame = scrollView.convert(signUpButton.frame, to: nil)
let contentOffsetY = scrollView.contentOffset.y // let padding = contentFrame.maxY - endFrame.minY
DispatchQueue.main.async { // if padding > 0 {
self.scrollView.setContentOffset(CGPoint(x: 0, y: contentOffsetY + padding + 16.0), animated: true) // let contentOffsetY = scrollView.contentOffset.y
} // DispatchQueue.main.async {
} // self.scrollView.setContentOffset(CGPoint(x: 0, y: contentOffsetY + padding + 16.0), animated: true)
} // }
} // }
// }
// }
func textFieldDidEndEditing(_ textField: UITextField) { func textFieldDidEndEditing(_ textField: UITextField) {
switch textField { switch textField {