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

标签 ios objective-c

我想将 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(superview) - 216(uipickerview))时,调试器控制台是清晰的。那里没有消息。

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

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

谢谢。

最佳答案

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

self.bottomCon.constant = -216; 

无论如何,如果您要对靠近屏幕底部的 View 进行约束,则应该对底部进行约束,而不是像问题中那样对顶部进行约束。如果您将常量设置为顶部,则它在不同的屏幕尺寸或方向上将不正确。

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

相关文章:

iphone - 将 subview 添加到 UITableViewCell 内容 View

ios - NSData 长度 - 隐式转换会丢失整数精度

ios - xctestcase 在通过预测试时运行测试

javascript - 开始为 iPhone 编程

ios - DBAccess:获取任何一个属性值的数组

android - 向不同的收款人汇款 Paypal

ios - 在文本字段中显示 XML 元素的数量

iphone - 将Integer设置为除零以外的任何值时为EXC_BAD_ACCESS

ios - 最终使用 PFFile(解析本地数据存储)保存在 PFObject 上?

ios - 推送通知到达时应用程序角标(Badge)图标未更新