Last active
July 5, 2017 12:53
-
-
Save timqzm/df7f462f12d6efd9070a19c72a52f932 to your computer and use it in GitHub Desktop.
How to set PKHUD above keyboard AND inputAccessoryView? https://stackoverflow.com/questions/44840460/how-to-set-pkhud-above-inputaccessoryview
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
var activeTextField: UITextField? | |
@IBAction func logIn(_ sender: Any) { | |
// ... | |
HUD.flash(.labeledError(title: "blabla", subtitle: "blablalba"), | |
onView: activeTextField?.inputAccessoryView, | |
delay: 1.0) | |
// ... | |
} | |
func textFieldDidBeginEditing(_ textField: UITextField) { | |
activeTextField = textField // if keyboard is shown, show HUD.flash under inputAccessoryView | |
} | |
func textFieldDidEndEditing(_ textField: UITextField) { | |
activeTextField = nil // if keyboard isn't shown, just show simple HUD.flash | |
} |
@PGLongo sorry, I didn't provide stuff like creating inputAccessoryView or setting textField delegate. Your example works absolutely the same as my screenshot above, if you make height smaller (I've tried 44). Well, that's full code:
import PKHUD
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var textField: UITextField!
var activeTextField: UITextField?
override func viewDidLoad() {
super.viewDidLoad()
textField.delegate = self
let customView = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 44))
customView.backgroundColor = .red
textField?.inputAccessoryView = customView
}
@IBAction func logIn(_ sender: Any) {
HUD.flash(.labeledError(title: "blabla", subtitle: "blablalba"),
onView: activeTextField?.inputAccessoryView,
delay: 1.0)
}
func textFieldDidBeginEditing(_ textField: UITextField) {
activeTextField = textField // if keyboard is shown, show HUD.flash under inputAccessoryView
}
func textFieldDidEndEditing(_ textField: UITextField) {
activeTextField = nil // if keyboard isn't shown, just show simple HUD.flash
}
}
@PGLongo I've pushed the project, if you want to play with it https://github.com/timqzm/PKHUD-above-inputAccessoryView
Maybe you want this:
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var textField: UITextField!
var activeTextField: UITextField?
let customView = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
override func viewDidLoad() {
super.viewDidLoad()
textField.delegate = self
customView.backgroundColor = .red
}
@IBAction func logIn(_ sender: Any) {
self.activeTextField?.inputView = self.customView
self.activeTextField?.reloadInputViews()
HUD.show(.progress, onView: self.activeTextField?.inputView)
}
func textFieldDidBeginEditing(_ textField: UITextField) {
activeTextField = textField
}
func textFieldDidEndEditing(_ textField: UITextField) {
activeTextField = nil // if keyboard isn't shown, just show simple HUD.flash
}
}
In this way the HUD replace the keyboard
@PGLongo
NO, I don't want replace the keyboard. I just want to see it like this:
Is there a way to do so?
You need to do this:
HUD.show(.progress, onView: UIApplication.shared.windows.last)
@PGLongo works perfectly, thx a lot!
You are welcome
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should work. If you don't create an inputAccessoryView the default is nil!