0

I tried using the following code to change the height of the keyboard (From https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html)

CGFloat _expandedHeight = 500;
NSLayoutConstraint *_heightConstraint = [NSLayoutConstraint constraintWithItem: self.keyboard attribute: NSLayoutAttributeHeight relatedBy: NSLayoutRelationEqual toItem: nil attribute: NSLayoutAttributeNotAnAttribute multiplier: 0.0 constant: _expandedHeight];
[self.keyboard addConstraint: _heightConstraint];

But it is not changing the height. (self.keyboard comes from @property (strong,nonatomic) Keyboard *keyboard;). I have also have a view inside the keyboard (self.keyboard.view1).

View1 also has constraints put in storyboard (Trailing Space to: Superview, Leading Space to: Superview, Bottom Space to: Superview, and Top Space to: Superview).

smecperson
  • 301
  • 1
  • 4
  • 15

1 Answers1

0

Should you not be setting the multiplier to 1.0 rather than 0.0?

CGFloat _expandedHeight = 500;
NSLayoutConstraint *_heightConstraint = [NSLayoutConstraint constraintWithItem: self.keyboard attribute: NSLayoutAttributeHeight relatedBy: NSLayoutRelationEqual toItem: nil attribute: NSLayoutAttributeNotAnAttribute multiplier: 1.0 constant: _expandedHeight];
[self.keyboard addConstraint: _heightConstraint];

Updated:

This link seems to have code for what you are trying to do. Here they add the constraint to the inputView of the keyboard controller.

iOS 8 Custom Keyboard: Changing the Height

Community
  • 1
  • 1
Rory McKinnel
  • 7,936
  • 2
  • 17
  • 28
  • I changed that, but it still does not change the height. I also changed `self.keyboard` to `self.view`. – smecperson Mar 03 '15 at 00:36
  • The note in the documentation says: "In iOS 8.0, you can adjust a custom keyboard’s height any time after its primary view initially draws on screen." So looks like you have to call your code after is displays on screen. Are you doing that? – Rory McKinnel Mar 03 '15 at 00:56
  • I noticed a comment elsewhere that in that function you should call [super updateViewConstraints] after your changes and not before. Might not make a difference and may be what you do already. Also I take it this function actually gets called? – Rory McKinnel Mar 03 '15 at 01:13
  • I did not put the changes before that, but when I did, nothing happened. I'm not sure if the function gets called and it's pretty difficult to tell since you can't log from a keyboard. – smecperson Mar 03 '15 at 01:36
  • You must be able to put a break point in the debugger for that function to see if its entered? – Rory McKinnel Mar 03 '15 at 01:49
  • I stop the app after it runs and slide down on home screen to test the keyboard, so that doesn't really work. – smecperson Mar 03 '15 at 01:53
  • assert (0) in the function. If it aborts you know it went in there. There is the chance it is not getting called which is most likely why nothing is happening. – Rory McKinnel Mar 03 '15 at 02:01
  • Add the line `assert(0);` in your `updateViewConstraints` function. It will make it abort if it executes that line. – Rory McKinnel Mar 03 '15 at 02:10
  • I added it, and the keyboard doesn't show up (it aborts). So, it is working. Also, the main view that has the keyboard in .xib file is called keyboard. Should I add the constraint to `self.keyboard` or `self.view`? – smecperson Mar 03 '15 at 02:15
  • Updated answer with link to code I think will help you. – Rory McKinnel Mar 03 '15 at 10:40
  • When I did that, it just crashes/ does same thing `assert(0);` does. – smecperson Mar 04 '15 at 01:49