4

We can create custom keyboard like this code in viewdidload as shown in apple developer site.

self.nextKeyboardButton = [UIButton buttonWithType:UIButtonTypeSystem];

[self.nextKeyboardButton setTitle:NSLocalizedString(@"Next Keyboard", @"Title for 'Next Keyboard' button") forState:UIControlStateNormal];
[self.nextKeyboardButton sizeToFit];
self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = NO;

[self.nextKeyboardButton addTarget:self action:@selector(advanceToNextInputMode) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:self.nextKeyboardButton];

NSLayoutConstraint *nextKeyboardButtonLeftSideConstraint = [NSLayoutConstraint constraintWithItem:self.nextKeyboardButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0];
NSLayoutConstraint *nextKeyboardButtonBottomConstraint = [NSLayoutConstraint constraintWithItem:self.nextKeyboardButton attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0];
[self.view addConstraints:@[nextKeyboardButtonLeftSideConstraint, nextKeyboardButtonBottomConstraint]];

However, there is 1 problem. When we run that program in portrait, the height of custom keyboard is around 220. Then we change to landscape. It is less than 220. Strangely, when I go back to portrait view, the height is no longer 220 and it is same as landscape height. It never go back to original height. So, is there a way to change the height of view to which we will add our subview?

Andrew
  • 15,357
  • 6
  • 66
  • 101
Khant Thu Linn
  • 5,905
  • 7
  • 52
  • 120

1 Answers1

8

That's probably a bug with apple's keyboard constraints problem, when rotating I'm seeing these messages in log:

 Unable to simultaneously satisfy constraints.
        Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
    (
        "<NSLayoutConstraint:0xfd04d80 V:[_UIKBCompatInputView:0xf97a580(216)]>",
        "<NSLayoutConstraint:0xe325bf0 V:[_UIKBCompatInputView:0xf97a580(162)]>"
    )

    Will attempt to recover by breaking constraint 
    <NSLayoutConstraint:0xfd04d80 V:[_UIKBCompatInputView:0xf97a580(216)]>

    Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
    The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

I already filed a bug for it.

woof
  • 1,288
  • 1
  • 11
  • 13
  • Hey woof - how are you logging with the keyboard extension? I have not been able to successfully print a log to the console with keyboard extensions – Spentak Jul 17 '14 at 20:38
  • Update to the latest Xcode should fix the log when you run on device. Sometimes it's still broken and you can try uninstall the app – woof Jul 18 '14 at 03:45
  • Been on latest Xcode with no success. Maybe its just the keyboard extension (vs other extensions) – Spentak Jul 18 '14 at 15:04
  • Apple fixed their constraints bug already, if you use autolayout and have problems with constraints, this will break as well. – woof Aug 12 '14 at 00:11
  • It shows every now and then no every time for me. When no such error comes up, there is no constraints in self.view when at viewDidAppear. – Henry Aug 13 '14 at 07:28
  • For me, the only solution that worked was this accepted answer from @skyline75489: http://stackoverflow.com/questions/24167909/ios-8-custom-keyboard-changing-the-height/25819565#comment40988935_25819565 – lifjoy Oct 02 '14 at 00:37