Skip to content

Commit 7f85fc1

Browse files
committed
Adding a scrollview to the addressupdate view
1 parent 3be0099 commit 7f85fc1

2 files changed

Lines changed: 160 additions & 117 deletions

File tree

Examples/GroceryExpress/AddressUpdateViewController.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extension URLSession {
9292

9393
/// A helper view to update the entry/exit geofences of a connection. This should only be used with connections that have entry and exit location triggers.
9494
final class AddressUpdateViewController: UIViewController {
95+
@IBOutlet private weak var scrollView: UIScrollView!
9596
@IBOutlet private weak var stackView: UIStackView!
9697
@IBOutlet private weak var enterAddressLabel: UILabel!
9798
@IBOutlet private weak var enterRadiusTextField: UITextField!
@@ -233,9 +234,37 @@ final class AddressUpdateViewController: UIViewController {
233234

234235
stackView.layoutMargins = .init(top: 20, left: 20, bottom: 0, right: 20)
235236
stackView.isLayoutMarginsRelativeArrangement = true
237+
238+
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow),
239+
name: UIResponder.keyboardWillShowNotification,
240+
object: nil)
241+
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide),
242+
name: UIResponder.keyboardWillHideNotification,
243+
object: nil)
244+
236245
update()
237246
}
238247

248+
override func viewWillDisappear(_ animated: Bool) {
249+
super.viewWillDisappear(animated)
250+
NotificationCenter.default.removeObserver(self)
251+
}
252+
253+
@objc private func keyboardWillShow(notification: Notification) {
254+
guard let userInfo = notification.userInfo else { return }
255+
var keyboardFrame:CGRect = (userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue
256+
keyboardFrame = self.view.convert(keyboardFrame, from: nil)
257+
258+
var contentInset:UIEdgeInsets = self.scrollView.contentInset
259+
contentInset.bottom = keyboardFrame.size.height + 20
260+
scrollView.contentInset = contentInset
261+
}
262+
263+
@objc private func keyboardWillHide(notification: Notification) {
264+
let contentInset:UIEdgeInsets = UIEdgeInsets.zero
265+
scrollView.contentInset = contentInset
266+
}
267+
239268
private func makeRequest(completion: @escaping (Data?, Error?) -> Void) {
240269
guard let userId = addressUpdate.userId,
241270
let entryPlacemark = addressUpdate.entryPlacemark,

0 commit comments

Comments
 (0)