8键盘高度和按键效果

8键盘高度和按键效果

本文介绍了iOS 8键盘高度和按键效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在XCode 6 Beta 5中更改键盘的高度.我搜索了代码,发现通过使用NSLayoutConstraint,我们可以更改键盘的高度,但不适用于我.

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.

这是我的代码:

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的视图中的所有视图都需要使用布局约束,因此您无法添加任何使用UIViewAutoresizing遮罩的子视图.如果要使用UIViewAutoresizing,只需添加如下所示的子视图,然后将所有其他视图添加到该视图.

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

这篇关于iOS 8键盘高度和按键效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:56