Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] 키보드 변경에 따른 UI 오류 수정 #132

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class ChatViewController: UIViewController {
private var dataSource: UICollectionViewDiffableDataSource<CollectionViewSection, ChatMessageCellModel>?
private let viewModel: ChatViewModel
private var cancellables: Set<AnyCancellable>
private var keyboardSize: CGRect?
private var keyboardHeight: CGFloat?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이름이 더 야미네유

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

야미!


public init(viewModel: ChatViewModel) {
self.viewModel = viewModel
Expand Down Expand Up @@ -170,22 +170,26 @@ public final class ChatViewController: UIViewController {
}

@objc private func keyboardUp(notification: NSNotification) {
guard let keyboardFrame: NSValue = notification
.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return }
keyboardSize = keyboardFrame.cgRectValue
guard let keyboardSize else { return }

UIView.animate(withDuration: 0.3) { [weak self] in
self?.view.frame.size.height -= keyboardSize.height
guard
let keyboardFrame: NSValue = notification
.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue
else { return }

var keyboardInset: CGFloat = 0
if let keyboardHeight {
keyboardInset = keyboardFrame.cgRectValue.height - keyboardHeight
} else {
keyboardInset = keyboardFrame.cgRectValue.height
Comment on lines +178 to +182
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var keyboardInset: CGFloat = 0
if let keyboardHeight {
keyboardInset = keyboardFrame.cgRectValue.height - keyboardHeight
} else {
keyboardInset = keyboardFrame.cgRectValue.height
var keyboardInset: CGFloat = keyboardFrame.cgRectValue.height
if let keyboardHeight {
keyboardInset -= keyboardHeight
}

이르케 하면 else까지는 없어두 될듯요 !!!

}
keyboardHeight = keyboardFrame.cgRectValue.height

self.view.frame.size.height -= keyboardInset
}

@objc private func keyboardDown() {
guard let keyboardSize else { return }

UIView.animate(withDuration: 0.3) { [weak self] in
self?.view.frame.size.height += keyboardSize.height
}
guard let keyboardHeight else { return }
self.view.frame.size.height += keyboardHeight
self.keyboardHeight = nil
}

@objc private func endEditingView() {
Expand Down