【问题标题】:iOS AutoLayout with masonry, failed to set child's bottom equal to parent bottom带有砌体的iOS AutoLayout,未能将子底部设置为父底部
【发布时间】:2016-09-02 12:13:44
【问题描述】:

我有一个在屏幕上显示为红色的父视图,在其中有一个为绿色的子视图。尝试将孩子定位到左下角时,以下代码失败。

    [superView addSubview:self];
    self.backgroundColor = [UIColor redColor];
    [self makeConstraints:^(MASConstraintMaker *make) {
        make.width.left.top.equalTo(superView);
        make.height.mas_equalTo(50);
    }];

    UIView *header = [[UIView alloc] init];
    [self addSubview:header];
    header.backgroundColor = [UIColor greenColor];
    [header makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(30);
        make.bottom.equalTo(self);
    }];

如何解决这个问题?

【问题讨论】:

    标签: objective-c iphone masonry-ios-osx


    【解决方案1】:

    如果您尝试为标题视图设置前导约束,例如

    mas.leading.equalTo(@0);
    

    【讨论】:

      猜你喜欢
      • 2018-11-23
      • 2011-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-30
      • 1970-01-01
      相关资源
      最近更新 更多