-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from cozzin/keyboardObserver
Add keyboard observer
- Loading branch information
Showing
4 changed files
with
82 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// KeyboardObserver.swift | ||
// Toaster | ||
// | ||
// Created by SeongHo Hong on 28/08/2019. | ||
// Copyright © 2019 Suyeol Jeon. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
final class KeyboardObserver { | ||
|
||
static let shared = KeyboardObserver() | ||
|
||
private(set) var didKeyboardShow: Bool = false | ||
|
||
init() { | ||
#if swift(>=4.2) | ||
let keyboardWillShowName = UIWindow.keyboardWillShowNotification | ||
let keyboardDidHideName = UIWindow.keyboardDidHideNotification | ||
#else | ||
let keyboardWillShowName = NSNotification.Name.UIKeyboardWillShow | ||
let keyboardDidHideName = NSNotification.Name.UIKeyboardDidHide | ||
#endif | ||
NotificationCenter.default.addObserver( | ||
self, | ||
selector: #selector(keyboardWillShow), | ||
name: keyboardWillShowName, | ||
object: nil | ||
) | ||
NotificationCenter.default.addObserver( | ||
self, | ||
selector: #selector(keyboardDidHide), | ||
name: keyboardDidHideName, | ||
object: nil | ||
) | ||
} | ||
|
||
@objc private func keyboardWillShow() { | ||
didKeyboardShow = true | ||
} | ||
|
||
@objc private func keyboardDidHide() { | ||
didKeyboardShow = false | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// UIApplication+Load.swift | ||
// Toaster | ||
// | ||
// Created by SeongHo Hong on 28/08/2019. | ||
// Copyright © 2019 Suyeol Jeon. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension UIApplication { | ||
|
||
open override var next: UIResponder? { | ||
UIApplication.runOnce | ||
return super.next | ||
} | ||
|
||
private static let runOnce: Void = { | ||
_ = KeyboardObserver.shared | ||
}() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters