Where to update auto-layout?

If I need to update a view frame, I can put this code in the -(void)viewWillLayoutSubviewsfollowing way:

- (void)viewWillLayoutSubviews {
    self.demoView.frame = CGRectMake(0, 0, 10, 10);
}

or in view mode - (void)layoutSubviews.

However, if I use autolayout now, and I need to update a dynamic object NSLayoutConstraintin the code, I don’t know where to put the code asself.demoWidthConstraint = 10

+4
source share
3 answers

You can configure existing restrictions anywhere, just call layoutIfNeededafter.

To revitalize a change, do, for example:

self.demoConstraint.constant = 10;
[UIView animateWithDuration:duration animations:^(void) {
    [self.view layoutIfNeeded];
}];
+9
source

. - IBOutlet Xcode .

, , . , .

. - viewDidMoveToSuperview . , . nil, , nil. , . .

, .

, , . nil.

, , .

+2

. , . .

0

All Articles