我需要迭代我的 View 的 super View 的约束。 view.superview.constraints 不是可选的,但我仍然收到“[AnyObject] 没有名为“Generator”的成员”错误。这是我的代码
func findViewHeightConstraint() {
if let sv = self.view.superview {
for constraint in sv.constraints {
}
}
}
View 约束定义为
func constraints() -> [AnyObject
所以不是可选的。尝试转换为 [NSLayoutConstraints] 会产生永远不会成功的警告。关于如何使用 Swift 迭代 View 约束有什么想法吗?
最佳答案
我犯了一个非常愚蠢的错误。自动完成功能一直试图告诉我一些事情,结果是
func findViewHeightConstraint() {
if let sv = self.view.superview {
for constraint in sv.constraints() {
}
}
}
关于ios - 在 Swift 中迭代 NSLayoutConstraints 会出现 "[AnyObject] does not have a member named ' Generator'"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31666983/