Search code examples
iosios8ios-app-extension

How to toggle a word selection view (change height) in iOS custom keyboard?


enter image description here

I'd to like to add a word selection view similar to the above in an iOS 8 custom keyboard.

  1. How can I change the keyboard view rectangle size dynamically? and
  2. notify the active app (such as the built-in Messages app) to reposition the input bar correspondingly?

UPDATE: based on this, the height of keyboard is customisable. How can that be possible?

enter image description here


Solution

  • It IS possible to change the size of the keyboard in the current iOS 8

    Taken verbatim from the documentation: "In iOS 8.0, you can adjust a custom keyboard’s height any time after its primary view initially draws on screen."

    To resize your custom keyboard, add a simple layout constraint.

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

    For more information look at Apple's prerelease documentation here!