evgenyneu / UnderKeyboard

An iOS libary for moving content from under the keyboard.
MIT License
128 stars 22 forks source link

Not Working Properly #9

Open WillMays1 opened 6 years ago

WillMays1 commented 6 years ago

Xcode 9 Swift 4

After setting the constraint to the bottom button in the view when clicking on a text field it just moves the button up and doesn't move the uiview at all

evgenyneu commented 6 years ago

Hi @WillMays1, thanks for reporting. If you want to move the view, you need to create a bottom constraint attached to the bottom of the view. All this library does is it increases the height of the constraint when the keyboard comes out. So if you attached the constraint to the button, it will go up with the keyboard, but this won't affect the view. Let me know how it goes.

WillMays1 commented 6 years ago

Ok it moves now but not all the way up probably about 75%

evgenyneu commented 6 years ago

What do you mean "not all the way up probably about 75%" sorry? Can you draw a picture?

WillMays1 commented 6 years ago

simulator screen shot - iphone 7 - 2017-09-20 at 21 08 23 simulator screen shot - iphone 7 - 2017-09-20 at 21 08 46

evgenyneu commented 6 years ago

Sorry, I don't quite understand what's going on there. :) I would try doing a demo app with a simple case, just to see how it works before applying to more complicated real app. Also, there is a demo app in this project, you might want to look how it works as well.

WillMays1 commented 6 years ago

Ok now its properly adding the space but not automatically moving the view up

evgenyneu commented 6 years ago

It's hard for me to say what's going on without knowing the details of the layout and the code. One can also use a workaround, instead of entering text in-place, open a modal dialog with a text input and let the user enter the text there. In this case there would be no need to move stuff around. Just an alternative.

WillMays1 commented 6 years ago

I have a UIView inside a UIScrollView. I created the bottom constraint. Attached the buttom constraint to the following IBOutlet:

@IBOutlet weak var bottomLayoutConstraint: NSLayoutConstraint! let underKeyboardLayoutConstraint = UnderKeyboardLayoutConstraint()

and I have this code in the viewDidLoad and it is still not working:

underKeyboardLayoutConstraint.setup(bottomLayoutConstraint, view: view, bottomLayoutGuide: bottomLayoutGuide)

Any ideas?

evgenyneu commented 6 years ago

Thanks for the info, but this is not enough information for me to know what's causing the issue. There are plenty of things that can go wrong, which depends on how one sets up the auto layout constraints. I'm repeating myself, but this library only increases the length of the auto layout constraint and makes it equal to the height of the keyboard (plus a margin). That's all it does. It does not scroll the scroll view to ensure your view is above the keyboard.

One way to troubleshoot the problem would be to go to your storyboard and manually set the height of the constraint equal to the height of the keyboard. This way one can see if changing the constraint length is enough.

Here is how one can get the height of the keyboard.