简体   繁体   English

什么是等效于 Objective-C 中的 getConstraintForFirstItem 的 swift 方法

[英]What is the swift method equivalent to getConstraintForFirstItem in Objective-C

Earlier I have used getConstraintForFirstItem to retrieve particular constraints in Objective-C like早些时候我使用getConstraintForFirstItem来检索 Objective-C 中的特定约束,例如

[[self.superview constraints] getConstraintForFirstItem:self andFirstAttributeis:NSLayoutAttributeBottom];

But cannot find equivalent method in swift to retrieve it and it says Value of type '[NSLayoutConstraint]' has no member 'getConstraintForFirstItem' .但是无法在 swift 中找到等效的方法来检索它,它说Value of type '[NSLayoutConstraint]' has no member 'getConstraintForFirstItem' Any solution for this issue?这个问题有什么解决方案吗?

try this尝试这个

You can use the firstItem, secondItem properties of [NSLayoutConstraint] to get the views related to the constraint.您可以使用 [NSLayoutConstraint] 的 firstItem、secondItem 属性来获取与约束相关的视图。

let  getConstraints =  self.view.superview!.constraints
        for constraint in getConstraints {
            if let getFirstItem = constraint.firstItem, getFirstItem.firstAttribute == NSLayoutConstraint.Attribute.bottom{
           break
        }
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM