Skip to content
This repository was archived by the owner on May 23, 2022. It is now read-only.

Commit e311cc7

Browse files
committed
Add enabled control to Demo
1 parent 7428cd8 commit e311cc7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Demo/Demo/ObserverViewController.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ final class KeyboardObserverViewController: UIViewController {
1717
override func viewDidLoad() {
1818
super.viewDidLoad()
1919

20-
navigationItem.title = "Observer"
21-
2220
keyboard.observe { [weak self] (event) -> Void in
2321
guard let s = self else { return }
2422
switch event.type {
2523
case .willShow, .willHide, .willChangeFrame:
24+
print("Fire: \(event.type)")
2625
let distance = UIScreen.main.bounds.height - event.keyboardFrameEnd.origin.y
2726
let bottom = distance >= s.bottomLayoutGuide.length ? distance : s.bottomLayoutGuide.length
2827

@@ -34,6 +33,20 @@ final class KeyboardObserverViewController: UIViewController {
3433
break
3534
}
3635
}
36+
37+
navigationItem.title = "Observer"
38+
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(self.rightButtonDidTap))
39+
}
40+
41+
func rightButtonDidTap() {
42+
let message = keyboard.isEnabled ? "Disable keyboard observing?" : "Enable keyboard ovserving?"
43+
44+
let controller = UIAlertController(title: "Keyboard observing", message: message, preferredStyle: .alert)
45+
controller.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
46+
controller.addAction(UIAlertAction(title: "OK", style: .default, handler: { [unowned self] _ in
47+
self.keyboard.isEnabled = !self.keyboard.isEnabled
48+
}))
49+
present(controller, animated: true, completion: nil)
3750
}
3851
}
3952

0 commit comments

Comments
 (0)