Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UIView to UIScrollView after UIScrollView init #341

Closed
zkhCreator opened this issue May 12, 2016 · 1 comment
Closed

Add UIView to UIScrollView after UIScrollView init #341

zkhCreator opened this issue May 12, 2016 · 1 comment

Comments

@zkhCreator
Copy link

I use the demo about UIScrollView,and I want to append a UIView a UIView after the UIScrollView init,like: I click a button,than there is a new UIView at the bottom of the UIScrollView. So I write the code like this:

- (void)clickButton{
    UIView *new = [[UIView alloc]init];
    new.backgroundColor = [UIColor blueColor];

    [self.scrollView.contentView addSubview:new];
    [new mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollView.lastBottom);
        make.left.equalTo(@0);
        make.right.equalTo(self.scrollView.contentView.mas_right);
        make.height.equalTo(@50);
    }];

    self.scrollView.lastBottom = new.mas_bottom;

    [self.scrollView.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.scrollView.lastBottom);
    }];
}

But there still an error like

(
    "<MASLayoutConstraint:0x7f97f431b360 UIView:content.bottom == UIView:newView.bottom>",
    "<MASLayoutConstraint:0x7f97f4341400 UIView:newView.top == UIView:newView.bottom>",
    "<MASLayoutConstraint:0x7f97f4341bb0 UIView:newView.height == 50>",
    "<MASLayoutConstraint:0x7f97f4315390 UIView:content.bottom == UIView:newView.bottom>"
)

Will attempt to recover by breaking constraint 
<MASLayoutConstraint:0x7f97f4341bb0 UIView:newView.height == 50>

It means I didnot update my constraint after update.How to solve the problem?

@robertjpayne
Copy link
Member

robertjpayne commented May 13, 2016

@zkh90644 mas_updateConstraints only updates matching constraints in this case you did not previously have a bottom.equalTo(self.scrollView.lastBottom) so it's actually creating a new constraint and you have two constraints.

You'll need to use mas_remakeConstraints and recreate all of them to get this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants