Я также делаю Клавиатуру и борюсь с проблемой высоты. Я пробовал все упомянутые решения, а также руководство по программированию приложений для расширения приложений, но не смог его исправить. У моей клавиатуры очень сложная иерархия. После борьбы я нашел решение, которое полностью работает на меня. Это своего рода хак, но я тестировал все сценарии даже при вращении устройства, и это прекрасно. Я думал, что это поможет кому-то, поэтому я размещаю свой код здесь.
// Keep this code inside the UIInputViewController
@implementation KeyBoardViewController
@property (strong, nonatomic) NSLayoutConstraint *heightConstraint;
// This method will first get the height constraint created by (Run time system or OS) then deactivate it and add our own custom height constraint.
(void)addHeightConstraint {
for (NSLayoutConstraint* ct in self.view.superview.constraints) {
if (ct.firstAttribute == NSLayoutAttributeHeight) {
[NSLayoutConstraint deactivateConstraints:@[ct]];
}
}
if (!_heightConstraint) {
_heightConstraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant: 300];
[_heightConstraint setPriority:UILayoutPriorityDefaultHigh];
[self.view addConstraint:_heightConstraint];
}else {
_heightConstraint.constant = 300;
}
if (_heightConstraint && !_heightConstraint.isActive) {
[NSLayoutConstraint activateConstraints:@[_heightConstraint]];
}
[self.view layoutIfNeeded];
}
(void)viewWillLayoutSubviews {
[self addHeightConstraint];
}