我有2个“姐妹视图”位于同一个父视图中,一个位于另一个(正在讲Y)之上。
第一个是屏幕的尺寸,下面的是屏幕底部的尺寸。
在动画上,底视图会升高并显示在屏幕上。
此动画应减小上方视图的高度。
我以为可以用NSLayoutConstraint
,但我无法工作。
现在我有以下内容:
let constraintString : String = String(format: "V:[tranlucentView][buttonContainer(%lg)]", buttonHeight * countOfButtons)
let viewsDict:NSDictionary = ["tranlucentView" : self.translucentView, "buttonContainer" : self.buttonContainer]
var constraints : NSArray = NSLayoutConstraint.constraintsWithVisualFormat(constraintString, options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDict)
self.view.addConstraints(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)
(
"<NSLayoutConstraint:0x198f6530 V:[UIView:0x198ef880]-(0)-[UIView:0x177b11e0]>",
"<NSLayoutConstraint:0x198f6600 V:[UIView:0x177b11e0(0)]>",
"<NSAutoresizingMaskLayoutConstraint:0x19f7f7f0 h=--& v=--& UIView:0x198ef880.midY == + 284>",
"<NSAutoresizingMaskLayoutConstraint:0x1983e4c0 h=--& v=--& V:[UIView:0x198ef880(568)]>",
"<NSAutoresizingMaskLayoutConstraint:0x19f7f260 h=--& v=--& UIView:0x177b11e0.midY == + 472>"
)
对我的问题有什么建议吗?
我自己找到了解决方案:
我需要translatesAutoresizingMaskIntoConstraints
给false
我上,以允许其调整大小。
另外,我需要为其宽度添加一个约束,否则宽度将变为0。
让constraintString:字符串=字符串(格式:“ V:| [tranlucentView] [buttonContainer(%lg)] |”,buttonHeight * countOfButtons)
self.translucentView.setTranslatesAutoresizingMaskIntoConstraints(false)
let viewsDict:NSDictionary = ["tranlucentView" : self.translucentView, "buttonContainer" : self.buttonContainer]
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(constraintString, options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDict))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[tranlucentView]|", options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDict))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句