auto layout modify multiplier of constraint programmatically

前端 未结 4 2061
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-06 13:37

How can I modify the multiplier of a constraint programmatically? I have set the following:

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_         


        
4条回答
  •  孤独总比滥情好
    2021-01-06 14:15

    For modifying multiplier I use switching between constraints method.
    You must Create constraints with different priorities else it will break the layout.

    Objective C

    NSLayoutConstraint *constraint1, *constraint2;
    
    // switch between constraints
    
    constraint1.active = NO; 
    constraint2.active = YES;
    [self.view layoutIfNeeded];
    

    Swift 2.0

    self.constraint1.active = true
    self.constraint2.active = false
    self.view.layoutIfNeeded()
    

提交回复
热议问题