I am using auto layout to position a custom progress bar (its simply a UIView with a background colour). Im not using a proper progress bar because I didnt want to have to fully customise it to my needs when a UIView will suffice.
Anyway I have told XCode to place the progress bar to the left, and a certain distance from the bottom. This positions it correctly but when I animate the width nothing happens. If I create a new UIVIew then animate that it works correctly. Are the constraints preventing this from animating? No constrains is placed upon 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){
}];
When you're using Auto Layout you shouldn't be using the setFrame:
method anymore. When you want to animate the 'frame', you'll have to animate the constraints. I suppose your Auto Layout constraints are defined in Interface Builder. First, make sure you have a width layout constraint added to your progress bar. Next, create an IBOutlet for this width layout constraint. You can now animate the constraint like this:
self.progressBarWidthLayoutConstraint.constant = 320;
[UIView animateWithDuration:1 animations:^{
[self.view layoutIfNeeded];
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With