iOS 更新约束

在更新约束时,要调用:

// 告诉self.view约束需要更新

  [self.view setNeedsUpdateConstraints];

  // 调用此方法告诉self.view检测是否需要更新约束,若需要则更新,下面添加动画效果才起作用

  [self.view updateConstraintsIfNeeded];

  

  [UIView animateWithDuration:0.3 animations:^{

    [self.view layoutIfNeeded];

  }];

 

//苹果推荐在updateViewConstraints方法中更新或者添加约束的

- (void)updateViewConstraints {

  [super updateViewConstraints];

}

posted @ 2016-04-05 16:23  tongyuling  阅读(3027)  评论(0编辑  收藏  举报