我的目的是使用约束将 UIPickerView 隐藏在屏幕下方,我可以忽略此调试器消息吗?



我想隐藏屏幕下方的UIPickerView,在本例中为3.5英寸显示屏。 了解了约束值后,终于知道应该为NSLayoutAttributeTop放什么数字了。

这是我的完整代码:

NSLayoutConstraint *constraint = [NSLayoutConstraint
                                  constraintWithItem:_pickerView
                                  attribute:NSLayoutAttributeTop
                                  relatedBy:NSLayoutRelationEqual
                                  toItem:self.view
                                  attribute:NSLayoutAttributeTop
                                  multiplier:1.0f
                                  constant:416.f];
[self.view addConstraint:constraint];

当我遇到我的iDevice时,它就像我预期的那样工作,除了...调试器控制台..它给了我这个消息:

2013-09-19 12:34:01.850 Constrain2[3546:c07] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x75490d0 h=--& v=--& V:[UIView:0x715a2f0(416)]>",
    "<NSLayoutConstraint:0x7159950 V:[UIPickerView:0x715a030(216)]>",
    "<NSLayoutConstraint:0x71597c0 V:|-(416)-[UIPickerView:0x715a030]   (Names: '|':UIView:0x715a2f0 )>",
    "<NSLayoutConstraint:0x715a7a0 UIPickerView:0x715a030.bottom == UIView:0x715a2f0.bottom>"
)

当我将常量值更改为 = 200.f 时,取自 416(超级视图)- 216(UIPICKERVIEW),调试器控制台很清楚。 那里没有消息。

是错误消息还是只是警告? 可以忽略吗? 是否可以隐藏屏幕下方的 UIPickerView,而不会让该消息出现在调试器控制台上?

当 UIPickerView 正确放置在其位置时,似乎不会出现该消息。 这是常数:200.f

谢谢。

不,你不应该忽视这一点——系统将尝试通过删除约束来修复它,但我不知道它是否总是会删除相同的约束,并给你你想要的结果。您似乎正在添加一个与您已有的约束冲突的约束(我在回答您之前的问题时评论了同样的问题)。在代码中添加新约束时,需要删除在 IB 中创建的约束(或多个)约束,这些约束将与之冲突。但是,要做你想做的事情,你甚至不应该添加新的约束,你应该修改你在IB中所做的约束。从错误消息来看,您似乎有一个从选取器底部到其超级视图底部的约束(长度为 0)。您应该为该约束创建一个IBOutlet(例如,我们将其称为bottomCon),然后在代码中修改其常量参数:

self.bottomCon.constant = -216; 
无论如何,如果您要对屏幕底部附近的视图进行约束,

则应将约束设置为底部,而不是像在问题中那样对顶部进行约束。如果将常量设置为顶部,则在不同的屏幕尺寸或方向下,它不会正确。

添加行

_pickerView.translatesAutoresizingMaskIntoConstraints = NO;

在添加约束之前。

相关内容

最新更新