gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:10:56 25 4
gpt4 key购买 nike

我想将 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>"
)

当我将常量值更改为取自 416 (superview) - 216 (uipickerview) 的 = 200.f 时,调试器控制台是清晰的。那里没有消息。

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

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

谢谢。

最佳答案

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

self.bottomCon.constant = -216; 

在任何情况下,如果您要对屏幕底部附近的 View 进行约束,则应将约束约束到底部,而不是像您在问题中所做的那样。如果您将常量设为顶部,则在不同的屏幕尺寸或方向上它不会正确。

关于ios - 我的目的是使用约束将 UIPickerView 隐藏在屏幕下方,我可以忽略此调试器消息吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18886897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com