DAKeyboardControl icon indicating copy to clipboard operation
DAKeyboardControl copied to clipboard

Possible to create example using Storyboard and AutoLayout?

Open ghost opened this issue 9 years ago • 2 comments

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.

ghost avatar May 20 '15 19:05 ghost

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

danielamitay avatar May 20 '15 21:05 danielamitay

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.

tfalencar avatar Jun 28 '15 17:06 tfalencar