What happens with constraints when a view is removed

前端 未结 6 1547
無奈伤痛
無奈伤痛 2020-12-07 21:31

The question I have is simple but I couldn\'t find any information in the documentation.

What happens with layout constraints when a view is removed from the view hi

6条回答
  •  攒了一身酷
    2020-12-07 22:24

    The constraints are removed. If you add A again, you will have to make new constraints for it, or if you save the constraints before you remove A, you can add them back. When I do something like this, I save the constraints like this for a view called view1:

    self.portraitConstraints = [NSMutableArray new];
    for (NSLayoutConstraint *con in self.view.constraints) {
        if (con.firstItem == self.view1 || con.secondItem == self.view1) {
           [self.portraitConstraints addObject:con];
        }
    }
    

提交回复
热议问题