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

iPhone X - Space above keyboard #10

Open
ezescaruli opened this issue Jan 22, 2018 · 7 comments
Open

iPhone X - Space above keyboard #10

ezescaruli opened this issue Jan 22, 2018 · 7 comments
Assignees

Comments

@ezescaruli
Copy link
Contributor

I've tried KeyboardConstraint in an iPhone X and it's having an issue when the keyboard appears. It looks like this (note the space between the sign up button and the keyboard):

image

I debugged the point in which the keyboard appears:

if ([self.firstItem conformsToProtocol:@protocol(UILayoutSupport)]) {

and had this:

(lldb) po [self firstItem]
<UILayoutGuide: 0x6000005acf60 - "UIViewSafeAreaLayoutGuide", layoutFrame = {{0, 0}, {375, 690}}, owningView = <UIView: 0x7fb63fc06df0; frame = (0 88; 375 724); autoresize = W+H; layer = <CALayer: 0x600000024b80>>>

and then I did:

(lldb) po [[self firstItem] conformsToProtocol:@protocol(UILayoutSupport)]
error: cannot find protocol declaration for 'UILayoutSupport'

The debugger doesn't find the UILayoutSupport protocol declaration, which is weird...

In runtime, what happens is that the above condition resolves to NO, so the execution never falls in the line that decrements keyboardHeight, and that's why we still have that extra space in the screenshot.

I've tried replacing the fix with this, and it seems to be working fine:

- (void)_keyboardDidChangeVisible:(NSNotification *)notification {
    ...

    if (notification.name == UIKeyboardWillShowNotification) {
        if (@available(iOS 11.0, *)) {
            UILayoutGuide *layoutGuide = [self layoutGuideItem];
            
            if (layoutGuide != nil) {
                keyboardHeight -= layoutGuide.owningView.safeAreaInsets.bottom;
            }
        }
    }

    ...
}

- (UILayoutGuide *)layoutGuideItem {
    if ([self.firstItem isKindOfClass:[UILayoutGuide class]]) {
        return self.firstItem;
    }
    
    if ([self.secondItem isKindOfClass:[UILayoutGuide class]]) {
        return self.secondItem;
    }
    
    return nil;
}
@ezescaruli
Copy link
Contributor Author

@markst What do you reckon? I know that the fix that we merged the other day worked for you, but for some reason it didn't work when I tried it (both in a simulator and a device), so I replaced it with the code I posted above to make it work.

But maybe I'm doing something wrong...?

@markst
Copy link
Contributor

markst commented Jan 22, 2018

Yo @ezescaruli. Thanks for the concise issue report.
We were aware of this when supporting iPhone X, see comments: #9 (comment)

Are you sure you're using the bottomLayoutGuide when attaching the keyboard constraint?
Since the bottom layout guide resolves to the safe area insets on an iPhone X.

The layoutGuide.length is considered when calculating the keyboard height:
https://github.com/Papercloud/KeyboardConstraint/blob/master/KeyboardConstraint/KeyboardAdjustConstraint.m#L67

@ezescaruli
Copy link
Contributor Author

@markst So, the sign up button bottom constraint looks like this:

image

The layoutGuide.length is considered when calculating the keyboard height

Yep that's right, however the issue in my case is that the execution is not reaching that line because both

[self.firstItem conformsToProtocol:@protocol(UILayoutSupport)]

and

[self.secondItem conformsToProtocol:@protocol(UILayoutSupport)]

resolve to NO. I think the reason is that the safe area layout guides are instances of UILayoutGuide, but don't conform to the UILayoutSupport protocol.

@markst
Copy link
Contributor

markst commented Jan 23, 2018

@ezescaruli as mentioned you need to use the bottomLayoutGuide as example:

image

@ezescaruli
Copy link
Contributor Author

@markst I don't have the bottom layout guide among the options 🤔

image

I could probably make it appear if I disable Use Safe Area Layout Guides in the storyboard file inspector, but that would not be ideal, would it?

@markst
Copy link
Contributor

markst commented Jan 23, 2018

Yup you need to disable safe area guides in the interface builder settings:

By all means have a crack at getting it to work fine for safe area insets.
Just be sure you don't break it for bottomLayoutGuide.

@ezescaruli
Copy link
Contributor Author

@markst Perfecto, I'll give a try and check if the fix I made above works for the bottom layout guide too 👍

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