Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyboardLayoutConstraint.swift using programmatically? #68

Closed
ghost opened this issue May 26, 2015 · 4 comments
Closed

KeyboardLayoutConstraint.swift using programmatically? #68

ghost opened this issue May 26, 2015 · 4 comments

Comments

@ghost
Copy link

ghost commented May 26, 2015

When working with the storyboard and the KeyboardLayoutConstraint.swift file, the keyboard is working great and the view attached to the bottom goes up. However I want to do everything pure programmatically.

I have something like below:

let views = ["messagesTableView": messagesTableView,"addMessageView": addMessageView,"addMessageTextField": addMessageTextField]

let keyboardViewV = KeyboardLayoutConstraint(item: addMessageView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.bottomLayoutGuide, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 0.0)
self.view.addConstraint(keyboardViewV)

let messagesViewV = NSLayoutConstraint.constraintsWithVisualFormat("V:|[messagesTableView][addMessageView]", options: NSLayoutFormatOptions(0), metrics: nil, views: views)
self.view.addConstraints(messagesViewV)

I've added all the constraints, but when I run my app, the keyboard goes up, but the addMessageView which is attached to the bottom layout guide, doesn't go up. The awakeFromNib function should fire, but nothing happens. What is going wrong? Is it even possible to do something like this programmatically? I tried a lot, but nothing works. I even changed the KeyboardLayoutConstraint.swift file to look for a better function than awakeFromNib, but this also doesn't work.

@ghost
Copy link
Author

ghost commented May 27, 2015

Well, finally I've found how to use this class programmatically.

Just replace awakeFromNib() with init() and you've to multiply the return value of updateConstant with minus 1. I guess this is due to the fact that the following code is reversed.

let keyboardViewV = KeyboardLayoutConstraint(item: addMessageView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.bottomLayoutGuide, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 0.0)
self.view.addConstraint(keyboardViewV)

@jamztang
Copy link
Contributor

Thanks for that. Would you like to provide a pull request on this? We'll just need to make sure both Storyboard/Code will do the job.

@ghost
Copy link
Author

ghost commented May 27, 2015

Well, it's just handy for people who want to use the file without a story board. So I don't think a pull request is ok. It doesn't add extra value to your great framework.

@schneiderandre
Copy link
Contributor

@RSDrsd thanks for sharing your solution!
Since no pull request is needed, I close the issue for now! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants