20170729 layout And constraint

系统报错
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'couldn't find a common superview for <UIButton: 0x7ff167f7a580; frame = (0 0; 0 0); opaque = NO; layer = <CALayer: 0x6080004290c0>> and <OrderBottomView: 0x7ff167e63560; frame = (0 617; 375 50); layer = <CALayer: 0x61000022ff40>>'
*** First throw call stack:

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configMessInterfaceViewWithTitle: @"确认下单" ];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = CHBackgroundColor;
    [self.view addSubview: self.payingBillsTableView ];
    [self.view addSubview: self.payingBillsBottomView ];

}



- (OrderBottomView *)payingBillsBottomView{
    if ( !_payingBillsBottomView ){
        _payingBillsBottomView = [[OrderBottomView alloc] initWithFrame: CGRectMake(0, kScreenHeight-50, kScreenWidth, 50 ) ];
    }
    return _payingBillsBottomView;
}

@implementation OrderBottomView

- (instancetype)init {
    if (self = [super init]) {
        self.backgroundColor = [UIColor whiteColor];
        [self setupView];
    }
    return self;
}



- (void)layoutSubviews {
    [super layoutSubviews];
    

    [self.payoffButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.equalTo(self);
        make.width.equalTo(@110);
    }];

    [self.totalPriceLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self.payoffButton.mas_left).offset(-16);
    }];
    
    [self.separateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
        make.height.equalTo(@0.3);
    }];
}

我觉得 是因为 ,
控件分配了 frame , 还没 add到 父视图上,控件的 子视图 layout constraints.
就GG.
约束 前, 必须 addSubview:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容