Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift自动布局:更新视图';s维_Swift_Autolayout_Pure Layout - Fatal编程技术网

Swift自动布局:更新视图';s维

Swift自动布局:更新视图';s维,swift,autolayout,pure-layout,Swift,Autolayout,Pure Layout,我正在使用 顺便说一句,我正在按代码做所有的布局 我有一个UIScrollView,它的功能类似于Facebook的新闻提要。我的滚动视图有一些子视图。让我们把它们叫做“卡片” 我在updateConstraints中设置了约束: for (i, view) in enumerate(self.viewsForAutoLayout) { /** Set view dimension **/ view.autoSetDimension(ALDimension.Width, toS

我正在使用

顺便说一句,我正在按代码做所有的布局

我有一个
UIScrollView
,它的功能类似于Facebook的新闻提要。我的滚动视图有一些子视图。让我们把它们叫做“卡片”

我在
updateConstraints
中设置了约束:

for (i, view) in enumerate(self.viewsForAutoLayout) {
    /** Set view dimension **/
    view.autoSetDimension(ALDimension.Width,  toSize: view.frame.width)
    view.autoSetDimension(ALDimension.Height, toSize: view.frame.height)

    /** Make 'em stack **/
    if i == 0 {
        view.autoPinEdgeToSuperviewEdge(
            ALEdge.Top,
            withInset: offset
        )
    } else {
        view.autoPinEdge(
            ALEdge.Top,
            toEdge: ALEdge.Bottom,
            ofView: self.viewsForAutoLayout[i - 1],
            withOffset: offset
        )
    }
}

self.setNeedsLayout()
layoutSubviews
中,我在这里调整卡的大小。从internet加载图像后(通过
NSURLConnection.sendAsynchronousRequest
,仅供参考,但与此主题无关)将更新它们各自的高度。之后,我将更新我的
滚动视图的高度

for (i, view) in enumerate(self.viewsForAutoLayout) {
    view.realignContent()
}

totalHeight += view.frame.size.height + offset

let size = CGSizeMake(AppConstants.ScreenSize.SCREEN_WIDTH, totalHeight)
self.scrollView.resizeContent(size) // extension
问题是它们没有正确对齐。这就像调用
setNeedsLayout()
(最终调用
layoutSubviews()
——如果我弄错了,请纠正我)根本没有对齐内容。我还确保调用了
setNeedsUpdateConstraints()

我试着在
布局子视图中调用它

view.autoSetDimension(ALDimension.Height, toSize: view.frame.height)
…但我得到某种警告:

Unable to simultaneously satisfy 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:0x1700918a0 V:[XXX.ContentBox:0x15fd63a80(928.986)]>",
    "<NSLayoutConstraint:0x170098bf0 V:[XXX.ContentBox:0x15fd63a80(1275.99)]>"
)
无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试着这样做:(1)看看每个约束,试着找出你不期望的约束;
(2) 找到添加了不需要的约束的代码,然后修复它。
(注意:如果您看到您不了解的NSAutoresizingMaskLayoutConstraints,
请参阅UIView属性的文档
翻译自动调整大小(从皮肤到肌肉)
(
"",
""
)
ContentBox
是卡的我的
UIView

卡看起来乱七八糟。我该怎么做才能正确对齐卡


如果代码有助于理解问题,我很乐意回答关于代码的旁注。:)侧面的建议也不错。

根据您看到的警告,在实例化卡视图时,您似乎需要设置
视图。translatesAutoResizezingMaskintoConstraints=false

我添加了它,但它不会改变效果:(