iphone - 更改constraintWithItem中的乘数时无法满足约束

标签 iphone ios cocoa-touch constraints containers

我正在尝试让我的容器 View 正常工作。问题是当将乘数更改为与 0.5 不同的值时,我得到:

Unable to simultaneously satisfy constraints.

例如,如果我将 *c2 multipier 更改为 0.4,将 *c8 更改为 0.6,则会出现上述错误。但如果我改回0.5,那就没问题了。我在这里做错了什么? 我有更多的限制,但它们是垂直布局的,所以我不认为它们是问题。

 NSLayoutConstraint *c1 = [NSLayoutConstraint constraintWithItem: contentView
                                                      attribute: NSLayoutAttributeLeft
                                                      relatedBy: NSLayoutRelationEqual
                                                         toItem:self.view
                                                      attribute:NSLayoutAttributeLeft
                                                     multiplier:1.0
                                                       constant:0.0];


NSLayoutConstraint *c2 = [NSLayoutConstraint constraintWithItem: contentView
                                                      attribute: NSLayoutAttributeWidth
                                                      relatedBy: NSLayoutRelationEqual
                                                         toItem:self.view
                                                      attribute:NSLayoutAttributeWidth
                                                     multiplier:.4
                                                       constant:0.0];


// detailView

NSLayoutConstraint *c7 = [NSLayoutConstraint constraintWithItem: detailView
                                                      attribute: NSLayoutAttributeRight
                                                      relatedBy: NSLayoutRelationEqual
                                                         toItem:self.view
                                                      attribute:NSLayoutAttributeRight
                                                     multiplier:1.0
                                                       constant:0.0];


NSLayoutConstraint *c8 = [NSLayoutConstraint constraintWithItem: detailView
                                                      attribute: NSLayoutAttributeWidth
                                                      relatedBy: NSLayoutRelationEqual
                                                         toItem:self.view
                                                      attribute:NSLayoutAttributeWidth
                                                     multiplier:.6
                                                       constant:0.0];

最佳答案

我使用 relatedBy:NSLayoutRelationGreaterThanOrEqual 取得了成功。

例如:

        [self.view addConstraint:

             [

              NSLayoutConstraint

              constraintWithItem: _accountRegisteredDateLabel
              attribute:NSLayoutAttributeWidth
              relatedBy:NSLayoutRelationGreaterThanOrEqual
              toItem:self.view
              attribute:NSLayoutAttributeWidth
              multiplier:.30
              constant:0


              ]

         ];

关于iphone - 更改constraintWithItem中的乘数时无法满足约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13138430/

相关文章:

iphone - Calier子类问题

IOS:如何恢复应用程序状态

ios - 在iOS 13中使用UISearchController时,状态栏在iOS中变为白色

objective-c - 释放 Core Foundation 对象引用

ios - 如何防止 NSTextAttachment 断行?

iphone - 保存登录凭据 Xcode

iphone - 找出对象是否已经在 NSMutableArray 中的最有效方法?

ios - 如何在 ios 中创建三角形对象

ios - 如何模拟以 pmkpromise 作为返回类型的方法

ios - UIGraphicsGetImageFromCurrentImageContext 泄漏