自动化布局完毕之后,也是进行frame的布局的,所以只需要在layoutIfNeeded之后获取frame就可以了
UIView *footerview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 1)]; footerview.backgroundColor = [UIColor blackColor]; UIView *redView = [UIView new]; redView.backgroundColor = [UIColor redColor]; [footerview addSubview:redView]; [redView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(-300); make.top.left.offset(0); make.height.equalTo(@70); }]; UIView *blueView = [UIView new]; blueView.backgroundColor = [UIColor blueColor]; [footerview addSubview:blueView]; [blueView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(-300); make.top.equalTo(redView.mas_bottom).offset(0); make.left.offset(0); make.height.equalTo(@300); // make.bottom.offset(0); }]; //一定要在获取frame之前调用layoutIfNeed [footerview layoutIfNeeded]; footerview.frame = CGRectMake(0, 0, self.view.bounds.size.width, CGRectGetMaxY(blueView.frame)); NSLog(@"%d",CGRectGetMaxY(blueView.frame));