CDAlertView play nice with IQKeyboardManager?

#37 · closed · 6 comments

View on GitHub ↗

p0tvin29

Hello, I'm trying to get the IQKeyboardManager plugin (https://github.com/hackiftekhar/IQKeyboardManager) to play nicely with your great CDAlertView plugin... when the keyboard pops up, I was hoping that the AlertView popup would shift up alittle to provide viewing capability of the textfield although there is some odd behaviour. When I first click on the textfield: ![screen1](https://user-images.githubusercontent.com/6618644/41778492-ecfa2cf8-75fc-11e8-8926-4d90f04df62f.png) When I click on the textfield for the second time, the popup moves to the top: ![screen2](https://user-images.githubusercontent.com/6618644/41778509-fb2c8eba-75fc-11e8-9577-25f124eefec1.png) Is it possible to move the popup just a tad higher then original position and on the first textfield click? Thanks

Comments

candostdagdeviren

Hello @p0tvin29, thanks for reporting the bug. I realized that it sends the `UIKeyboardWillShow` notification whenever I click the TextField. This causes the popup to move upwards. I'll fix it soon and release a new version.

p0tvin29

Thank you! Great job with the plugin!

candostdagdeviren

I fixed in version [0.8.3](https://github.com/candostdagdeviren/CDAlertView/releases/tag/0.8.3). It's already published. You can update your CocoaPods repo and give it a try. Feel free to reopen the issue if the problem is still there. I hope it helps. :)

p0tvin29

I noticed the keyboard still covers the textfield as shown in my screen shot below...is this an issue with the keyboard plugin now or are you able to fix this on your end? ![screen3](https://user-images.githubusercontent.com/6618644/41805814-8fd955a8-767e-11e8-8200-16d0bc7559ce.png)

candostdagdeviren

AFAIK, IQKeyboardManager shifts the whole screen up while editing the TextField. So, I don't know how does it effect actually. I just use basic calculation with keyboard frame height and the visibility of textField. I guess, there should be a problem in the calculation. I don't have a free time soon, feel free to open a PR :)

steveakopyan

I had the exact same problem and upgrading to version 0.8.3 didn't help either. I looked into the keyboardWillShow method and made some modifications. It now works for me (I hard-coded it so that the popup moves up leaving a margin of 10 points between itself and the keyboard; feel free to change this to your liking). See if this helps. Please note that for the lack of time I only tested it on iPhone. ``` @objc func keyboardWillShow(_ notification: Notification) { if isKeyboardVisible { return } isKeyboardVisible = true guard let userInfo = notification.userInfo else { return } guard let keyboardSize = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } if keyboardSize.origin.y >= popupView.frame.origin.y + popupView.frame.height + 10 { return } popupCenterYPositionBeforeKeyboard = popupView.center.y let difference = popupView.frame.origin.y + popupView.frame.height - keyboardSize.origin.y popupView.center.y -= (difference + 10) } ```