candostdagdeviren / CDAlertView

Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift
https://candostdagdeviren.github.io/CDAlertView/
MIT License
1.14k stars 86 forks source link

CDAlertView play nice with IQKeyboardManager? #37

Closed p0tvin29 closed 6 years ago

p0tvin29 commented 6 years ago

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

When I click on the textfield for the second time, the popup moves to the top: screen2

Is it possible to move the popup just a tad higher then original position and on the first textfield click?

Thanks

candostdagdeviren commented 6 years ago

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 commented 6 years ago

Thank you! Great job with the plugin!

candostdagdeviren commented 6 years ago

I fixed in version 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 commented 6 years ago

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

candostdagdeviren commented 6 years ago

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 commented 6 years ago

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)
    }