【问题标题】:IOS 8 Keyboard Height And Key EffectsIOS 8 键盘高度和按键效果
【发布时间】:2014-10-14 21:49:15
【问题描述】:

我想在 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];

【问题讨论】:

  • 我将此代码放在 viewDidAppearkeypress 方法中,但对我也不起作用
  • @lkambad ,如果您使用 xcode beta 3 或 beta 4,我认为它不会发生。即使我尝试过,但高度没有变化。有些在 beta 5 和 beta 6 上取得了成功。
  • @codeIgnitor 我记下我使用的是 xcode 6 beta 5....但不工作
  • @codeIgnitor 还有很多其他用户遇到同样的问题只需访问stackoverflow.com/questions/25486802/…

标签: ios objective-c iphone keyboard


【解决方案1】:

为了让所有添加到 UIInputViewController 视图的视图能够正常工作,需要使用布局约束,因此您不能添加任何使用 UIViewAutoresizing 掩码的子视图。如果您想使用 UIViewAutoresizing,只需添加一个如下所示的子视图,然后将所有其他视图添加到该视图。

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

【讨论】:

    猜你喜欢
    • 2014-11-24
    • 1970-01-01
    • 2015-06-20
    • 2014-11-17
    • 1970-01-01
    • 2015-03-05
    • 2015-11-14
    • 1970-01-01
    • 2014-12-11
    相关资源
    最近更新 更多