-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Animating a view inside a cell : First init #40
Comments
Ok, noticed that first rows were pretty low to see the animation on first run. I inverted the numbers so rows can go from 100% to 0%. |
@lluisgerard thanks for the very detailed issue info! I think adding Let me know if that helps |
Thanks @cloudkite, I will post a GIF here showing both cases because is hard to explain in words. With |
In fact, when you set the percentage the first thing the code does is
Using According to documentation:
I will continue searching for more information about this to find an elegant way, will post something asap, thanks. |
Ok, here is what I found:
With this in mind, I removed the What I did then is call
(man, this thread is getting large, sorry 🐙) |
@lluisgerard I think you having problems as setting percentage could happen before the cell has a frame. Try the following: in - (void)layoutSubviews {
[super layoutSubviews];
[self.animatedView setPercentage:_percentage];
}
- (void)setPercentage:(float)percentage {
_percentage = percentage;
[self setNeedsLayout];
} in - (void)setPercentage:(float)percentage {
_percentage = percentage;
self.numberLabel.text = [NSString stringWithFormat:@"%i%%", (int)_percentage];
self.animateConstraint.equalTo(@0);
[self layoutIfNeeded];
float width = CGRectGetWidth(self.frame) * (_percentage / 100.0);
self.animateConstraint.equalTo(@(width));
[UIView animateWithDuration:1.0f
delay:0.0f
usingSpringWithDamping:0.4f
initialSpringVelocity:0.9f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self layoutIfNeeded];
} completion:nil];
} |
I tested it with above code, seems fix the issues as far as I can tell. BTW what are you using for creating gifs? |
Amazing! that's what I was missing the whole time! Gifrocket: http://www.gifrocket.com Is the first time I use it but works very well. I think you can record the video with QuickTime but I'm using a payed app iShowU. |
Thanks to @cloudkite I finally found that you can start the animation in layoutSubviews cell's method so it always starts when everything is set. Related thread on Masonry SnapKit/Masonry#40
Just pushed these new changes to the example. 🎉 ✌️ |
I removed the |
First of all, I don't know if this is really an issue of Masonry or an Auto Layout thing.
I'd been doing some tests animating things with Masonry and after some tweaking it usually works like a charm and is pretty fast. I want to share one of these tests with you which is perfect to show the issue I had and the workaround used.
https://github.com/lluisgerard/Masonry-Animated-Cell
As you can see here. I have a view that starts always at width 0 and grows to the pixel equivalent percentage (from 0 to 300 px).
The basic code for this animation is where self.animateConstraint is animated:
What happens is that when you start the app for the first time (aka load the tableview) the growing view doesn't animate at all. It just appears on the cell with the end state of the animation.
I don't know the best way to approach this, maybe there is something that I'm missing like a trigger when the view is completely loaded and constraints are set (delegates?). I even found other issues that I cannot replicate now, like the bar started to grow while the whole view was being set by autolayout (I think I was using updateConstraints then).
Ok, the solution (or workaround) I found was to do this only the first init:
As you can see, delay is set to 0 seconds but the
dispatch_after
is enough to activate the first animation. You can download my example project, comment the dispatch, you will see that nothing is animated on the first load then.You can see the whole code here https://github.com/lluisgerard/Masonry-Animated-Cell/blob/master/AnimateLayouts/LLGAnimatedView.m
I'm sure I'm missing something here to know when the autolayout finished doing it's job (maybe tracking self.frame width and height?). Anyway, I hope that at least somebody can enjoy my example :)
The text was updated successfully, but these errors were encountered: