From 5ae5741ffaa01fbcaa7c1f60550cca925263f517 Mon Sep 17 00:00:00 2001 From: krugerk <4656811+krugerk@users.noreply.github.com> Date: Wed, 22 Oct 2025 09:20:15 +0200 Subject: [PATCH 1/2] laying out the gallery in sync with the keyboard --- BeeSwift/Gallery/GalleryViewController.swift | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/BeeSwift/Gallery/GalleryViewController.swift b/BeeSwift/Gallery/GalleryViewController.swift index 85f087ae..e2522649 100644 --- a/BeeSwift/Gallery/GalleryViewController.swift +++ b/BeeSwift/Gallery/GalleryViewController.swift @@ -154,6 +154,16 @@ class GalleryViewController: UIViewController { name: CurrentUserManager.NotificationName.signedIn, object: nil ) + NotificationCenter.default.addObserver( + self, + selector: #selector(self.keyboardWillShow), + name: UIResponder.keyboardWillShowNotification, + object: nil) + NotificationCenter.default.addObserver( + self, + selector: #selector(self.keyboardWillHide), + name: UIResponder.keyboardWillHideNotification, + object: nil) self.view.addSubview(self.stackView) stackView.snp.makeConstraints { (make) -> Void in make.top.left.right.equalToSuperview() @@ -462,3 +472,29 @@ extension GalleryViewController { } } } + + +private extension GalleryViewController { + @objc func keyboardWillShow(_ notification: Notification) { + guard self.searchBar.searchTextField.isEditing else { return } + moveViewWithKeyboard(notification: notification, keyboardWillShow: true) + } + func moveViewWithKeyboard(notification: Notification, keyboardWillShow: Bool) { + guard let userInfo = notification.userInfo else { return } + guard + let keyboardDuration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double + else { return } + guard + let curve = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? UInt + else { return } + let animationOptions = UIView.AnimationOptions(rawValue: curve) + UIView.animate(withDuration: keyboardDuration, + delay: 0, + options: animationOptions) { [weak self] in + self?.view.layoutIfNeeded() + } + } + @objc func keyboardWillHide(_ notification: Notification) { + moveViewWithKeyboard(notification: notification, keyboardWillShow: false) + } +} From 9b328683f95e5d650057b0b72369536003f6b8e1 Mon Sep 17 00:00:00 2001 From: krugerk <4656811+krugerk@users.noreply.github.com> Date: Wed, 22 Oct 2025 09:34:16 +0200 Subject: [PATCH 2/2] applied code formatting --- BeeSwift/Gallery/GalleryViewController.swift | 27 ++++++++------------ 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/BeeSwift/Gallery/GalleryViewController.swift b/BeeSwift/Gallery/GalleryViewController.swift index e2522649..d8192644 100644 --- a/BeeSwift/Gallery/GalleryViewController.swift +++ b/BeeSwift/Gallery/GalleryViewController.swift @@ -158,12 +158,14 @@ class GalleryViewController: UIViewController { self, selector: #selector(self.keyboardWillShow), name: UIResponder.keyboardWillShowNotification, - object: nil) + object: nil + ) NotificationCenter.default.addObserver( self, selector: #selector(self.keyboardWillHide), name: UIResponder.keyboardWillHideNotification, - object: nil) + object: nil + ) self.view.addSubview(self.stackView) stackView.snp.makeConstraints { (make) -> Void in make.top.left.right.equalToSuperview() @@ -473,28 +475,21 @@ extension GalleryViewController { } } - -private extension GalleryViewController { - @objc func keyboardWillShow(_ notification: Notification) { +extension GalleryViewController { + @objc fileprivate func keyboardWillShow(_ notification: Notification) { guard self.searchBar.searchTextField.isEditing else { return } moveViewWithKeyboard(notification: notification, keyboardWillShow: true) } - func moveViewWithKeyboard(notification: Notification, keyboardWillShow: Bool) { + fileprivate func moveViewWithKeyboard(notification: Notification, keyboardWillShow: Bool) { guard let userInfo = notification.userInfo else { return } - guard - let keyboardDuration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double - else { return } - guard - let curve = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? UInt - else { return } + guard let keyboardDuration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double else { return } + guard let curve = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? UInt else { return } let animationOptions = UIView.AnimationOptions(rawValue: curve) - UIView.animate(withDuration: keyboardDuration, - delay: 0, - options: animationOptions) { [weak self] in + UIView.animate(withDuration: keyboardDuration, delay: 0, options: animationOptions) { [weak self] in self?.view.layoutIfNeeded() } } - @objc func keyboardWillHide(_ notification: Notification) { + @objc fileprivate func keyboardWillHide(_ notification: Notification) { moveViewWithKeyboard(notification: notification, keyboardWillShow: false) } }