iOS:如何在没有someView.addConstraints的情况下使用constraintsWithVisualFormat?
我遇到了一个问题,我不知道如何使用旧函数iOS:如何在没有someView.addConstraints的情况下使用constraintsWithVisualFormat?,ios,swift,uiscrollview,autolayout,Ios,Swift,Uiscrollview,Autolayout,我遇到了一个问题,我不知道如何使用旧函数constraintsWithVisualFormat,而不在某些特定视图上使用addConstraints函数 头文件显示: 此方法将在将来的版本中被弃用,并应 避免。改为使用+[NSLayoutConstraint activateConstraints:] 好的,我对类函数很满意,但我是否误解了这里的某些内容?我用纯AutoLayout和UIScrollView()解决了我的问题 所以我可以这样做,现在一切都会好起来,但将来不会: let views
constraintsWithVisualFormat
,而不在某些特定视图上使用addConstraints
函数
头文件显示:
此方法将在将来的版本中被弃用,并应
避免。改为使用+[NSLayoutConstraint activateConstraints:]
好的,我对类函数很满意,但我是否误解了这里的某些内容?我用纯AutoLayout
和UIScrollView
()解决了我的问题
所以我可以这样做,现在一切都会好起来,但将来不会:
let views = ["containerView" : self.containerView]
self.scrollView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[containerView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views))
self.scrollView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[containerView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views))
此方法是否未在发动机罩下设置NSLayoutConstraint
的firstItem
或secondItem
对于本例,如何模拟正确的VF
我知道如何使用新的锚语法创建相同的约束,但我对将来如何使用VFL很好奇 使用VisualFormat的
约束没有问题。标题只是建议您将self.scrollView.addConstraints(…)
替换为NSLayoutConstraint.activateConstraints(…)
引擎盖下的[containerView]
是您的容器视图,|
是超级视图-这是第一项
,而第二项
,是超级视图
。我一直都不知道。Thx很多。@vacawama我知道如何使用activateConstraints
,但我的观点是superview,我认为它是通过调用特定视图上的旧addConstraints
函数添加到约束中的。
let views = ["containerView" : self.containerView]
NSLayoutConstraint.activateConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[containerView]|", options: [], metrics: nil, views: views))
NSLayoutConstraint.activateConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[containerView]|", options: [], metrics: nil, views: views))