First add contraindications outside the animation block, then call updateConstraints and inside the animation block, call layoutIfNeeded. Streamline it will
CGFloat _expandedHeight = 500; NSLayoutConstraint *_heightConstraint = [NSLayoutConstraint constraintWithItem: self.view attribute: NSLayoutAttributeHeight relatedBy: NSLayoutRelationEqual toItem: nil attribute: NSLayoutAttributeNotAnAttribute multiplier: 0.0 constant: _expandedHeight]; [self.view addConstraint: _heightConstraint]; [self.view needsUpdateConstraints]; [UIView animateWithDuration:2 animations:^{ [self.view layoutIfNeeded]; }];
source share