Animating View Widths Using Auto Layout

I use autoscaling to place a custom progress bar (its just a UIView with background color). I do not use the correct progress bar because I did not want to fully customize it to my needs when the UIView is sufficient.

In any case, I told Xcode to place the progress bar to the left and some distance from the base. This is true, but when I change the width, nothing happens. If I create a new UIVIew, then revive that it works correctly. Are the restrictions hindering this revival? No restrictions fit on the width at all

[UIView animateWithDuration:startingGameSeconds delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^(void) { progressBar.frame = CGRectMake(progressBar.frame.origin.x, progressBar.frame.origin.y, 320, progressBar.frame.size.height); } completion:^(BOOL finished){ }]; 
+4
source share
1 answer

When using auto-layout, you should no longer use the setFrame: method. When you want to animate the "frame", you will need to animate the limitations. I believe your Auto Layout restrictions are defined in Interface Builder. First, make sure the layout width limit is added to your progress bar. Then create an IBOutlet for this layout width limit. Now you can animate the restriction as follows:

 self.progressBarWidthLayoutConstraint.constant = 320; [UIView animateWithDuration:1 animations:^{ [self.view layoutIfNeeded]; }]; 
+8
source

Source: https://habr.com/ru/post/1501842/


All Articles