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

Possible to create example using Storyboard and AutoLayout? #90

Open
ghost opened this issue May 20, 2015 · 2 comments
Open

Possible to create example using Storyboard and AutoLayout? #90

ghost opened this issue May 20, 2015 · 2 comments

Comments

@ghost
Copy link

ghost commented May 20, 2015

Trying to use this control in a new app that requires Storyboard/Autolayout.
I see you added a 2nd block 'constraintBasedActionHandler' to each method, but I don't see any examples on how to properly use it.

I tried this but the message input view I have never moves:

        self.view.addKeyboardPanningWithFrameBasedActionHandler(nil, constraintBasedActionHandler: { [unowned self] (keyboardFrameInView, opening, closing) -> Void in
            //self.messageToolbar.bottomConstraint.constant = -keyboardFrameInView.size.height // Also tried this
            self.messageToolbar.bottomConstraint.constant = self.view.frame.size.height - keyboardFrameInView.size.height
            self.view.updateConstraintsIfNeeded()
            self.view.layoutIfNeeded()
        })

It does work when I set the frame manually and not use the auto layout constraint, but I am having to many issues with different devices and am trying to steer clear of setting frames directly.

@danielamitay
Copy link
Owner

I personally do not use Storyboards/AutoLayout, so if someone else would like to supply an example, that would be great!

@tfalencar
Copy link

Here's an example of doing this with AutoLayout:

Say you have a constraint fixing a UIView to the bottom of the screen, and we want this view to 'follow' the keyboard as we drag it down:

[self.view addKeyboardPanningWithFrameBasedActionHandler:nil 
constraintBasedActionHandler:^(CGRect keyboardFrameInView, BOOL opening, BOOL closing) 
{
        NSLog(@"constraint handler: %f", keyboardFrameInView.origin.y);
        __typeof__(self) strongSelf = weakSelf;
        if (strongSelf)
        {
            strongSelf.inputFieldBottomConstraint.constant = strongSelf.view.frame.size.height - keyboardFrameInView.origin.y;
            [strongSelf.view layoutIfNeeded];
        }
    }];

If it doesn't work its probably a good idea to test if the Autolayout constraint is correct.

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