IOS 8 键盘高度和按键效果

标签 ios objective-c iphone keyboard

我想在 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/

相关文章:

ios - SCNPlane 上的 GADBannerView 可以吗?

c++ - 将 C++ 库与 Objective-C 应用程序链接和使用

iphone - 调整 iPad CSS 布局以适应 iPhone 屏幕

ios - 如何获取 UICollectionView header 的 IndexPath?

ios - 使用 ionic 创建 IPA 文件

ios - Google admob GADBannerView 无法识别的选择器

iphone - 是否可以将 UIGestureRecognizer 附加到子类 UIImageView?

iphone - 53 * .01 = .531250

ios - 如何卡住 View 直到某个值为真?

ios - 如何向人们发送我的应用测试版?