Ikambad
Ikambad

Reputation: 104

IOS 8 Keyboard Height And Key Effects

I want to change the height of keyboard in XCode 6 Beta 5. I searched code and found that by using NSLayoutConstraint, we can change the height of it but not work for me.

This is my code:

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];

Upvotes: 4

Views: 740

Answers (1)

coder
coder

Reputation: 11

In order for this to work all the views that are added to the UIInputViewController's view need to use layout constraints so you can't add any subviews that use UIViewAutoresizing masks. If you want to use UIViewAutoresizing just add a subview like below then add all of your other views to that view.

UIView *mainView = [[UIView alloc] initWithFrame:self.view.bounds];

[mainView setTranslatesAutoresizingMaskIntoConstraints:NO];

[self.view addSubview:mainView];

NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:mainView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0.0];

NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:mainView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0.0];

[self.view addConstraints:@[widthConstraint, heightConstraint]];

Upvotes: 1

Related Questions