我想在 XCode 6 Beta 5 中更改键盘的高度。我搜索了代码,发现通过使用 NSLayoutConstraint
,我们可以更改它的高度,但对我不起作用。
这是我的代码:
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];
最佳答案
为了使其正常工作,所有添加到 UIInputViewController View 的 View 都需要使用布局约束,因此您不能添加任何使用 UIViewAutoresizing 掩码的 subview 。如果您想使用 UIViewAutoresizing,只需像下面这样添加一个 subview ,然后将所有其他 View 添加到该 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]];
关于IOS 8 键盘高度和按键效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25423323/