无法更改UIInputView高度 [英] Unable to change UIInputView height

查看:528
本文介绍了无法更改UIInputView高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有只有两个重载方法简单UIInputViewController子类。我用这个输入视图控制器为 inputAccessoryViewController 我UIViewController子类变成第一响应者。我试图通过苹果文档建议增加约束指定inputView的高度。
问题是,我的约束不工作,我得到的,当被加入我的约束自动布局例外

I have a simple UIInputViewController subclass with only two overridden methods. I use this input view controller as inputAccessoryViewController on my UIViewController subclass which becomes first responder. I try to specify height of inputView by adding constraint as Apple documentation recommends. Problem is that my constraint doesn't work and I get autolayout exception when my constraint is being added

Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
...
(
    "<NSLayoutConstraint:0x178aa1d0 V:[UIInputView:0x178a4ae0(0)]>",
    "<NSLayoutConstraint:0x178b9520 V:[UIInputView:0x178a4ae0(500)]>"
)
Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x178b9520 V:[UIInputView:0x178a4ae0(500)]>

我认为这意味着系统中已经添加了一个零高度约束输入视图(因为它是与零高度创建)。现在,他们发生冲突,自动布局打破我的约束来解决这个问题。

Which I think means that system already added a zero height constraint to the input view (because it is created with zero height). Now they conflict and autolayout breaks my constraint to fix the issue.

当我尝试使用它作为 inputViewController 我的视图控制器(只是用于测试目的),我得到相同的异常,而是零高度是216像素。这也打破我的约束和高度保持默认值。

When I try to use it as inputViewController of my view controller (just for test purposes), I get same exception but instead of zero height it is 216 px. It also breaks my constraint and the height remains default.

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.inputView.translatesAutoresizingMaskIntoConstraints = NO;
    self.inputView.backgroundColor = [UIColor redColor];
}

- (void)updateViewConstraints {

    CGFloat _expandedHeight = 500;
    NSLayoutConstraint *_heightConstraint = 
    [NSLayoutConstraint constraintWithItem:self.view
                                 attribute:NSLayoutAttributeHeight
                                 relatedBy:NSLayoutRelationEqual
                                    toItem:nil
                                 attribute:NSLayoutAttributeNotAnAttribute
                                 multiplier:0.0
                                   constant: _expandedHeight];
    [self.inputView addConstraint: _heightConstraint];

    [super updateViewConstraints];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.view setNeedsUpdateConstraints];
}

其结果是,我不能改变输入附件视图的高度。有没有人在它成功吗?显然,苹果文档提供任何帮助...

As a result, I am not able to change input accessory view height. Has anyone succeed in it? Obviously, Apple documentation provides no help...

推荐答案

当你犯了一个观点一个UITextView的输入辅助认为,只要文本视图成为第一响应者,一个高度约束将添加自动设置为任何被作为发送帧的高度。例如:

When you make a view the input accessory view of a UITextView, as soon as the text view becomes first responder, a height constraint is added automatically set to whatever was sent as the frame height. For example:

let inputView = UIInputView(frame: CGRectMake(0, 0, view.bounds.width, 200), inputViewStyle: .Default)
someTextView.inputAccessoryView = inputView
someTextView.becomeFirstResponder()
assert((inputView.constraints().last as NSLayoutConstraint).constant == 200)

您可以在事后修改此约束。

You can modify this constraint after the fact.

这篇关于无法更改UIInputView高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆