【问题标题】:AutoLayout container relative position not recognised under ios8 beta 4ios8 beta 4下无法识别AutoLayout容器相对位置
【发布时间】:2014-07-28 18:29:11
【问题描述】:

在我看来,我会像这样初始化一个视图:

UIView *statsView = [[UIView alloc] initWithFrame:CGRectMake(10, 130, 200, 12)];

在这个视图中,我创建了 3 个包含在前一个视图中的自动布局子视图。

    for (UIButton* v in [statsView subviews]) {
        v.translatesAutoresizingMaskIntoConstraints = NO;
       [statsView addSubview:v];
    }
    NSDictionary *views = @{@"reposts": v1,
                            @"likes": v2,
                            @"comments": v3
                            };
    [statsView addConstraints:[NSLayoutConstraint
                               constraintsWithVisualFormat:@"H:|[reposts][likes][comments]"
                               options:NSLayoutFormatAlignAllTop| NSLayoutFormatAlignAllBottom
                               metrics:0
                               views:views]];

在 IOS7 上,容器的 Y 位置是 130(在 initWithFrame 中定义),但在 ios8 上,Y 位置看起来像“0”。

有什么想法吗?

【问题讨论】:

  • 这里也一样。你能想出什么办法吗?

标签: objective-c position autolayout ios8 nslayoutconstraint


【解决方案1】:

我问了一个关于同样问题的其他问题,Saldorino 给了我一个很好的答案

Xcode6 - Autolayout view in an other autolayout view

问题在于缺少垂直位置约束。

[statsView addConstraints:[NSLayoutConstraint
                           constraintsWithVisualFormat:@"V:|[comments]"
                           options:0
                           metrics:0
                           views:views]];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 2014-11-03
    • 1970-01-01
    • 2012-12-09
    • 1970-01-01
    • 2017-07-17
    • 1970-01-01
    相关资源
    最近更新 更多