Skip to content
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

Double the RBBSpringAnimation "sampling rate" for smoother animations. #21

Open
orj opened this issue Jul 1, 2015 · 4 comments
Open
Labels

Comments

@orj
Copy link

orj commented Jul 1, 2015

While using RBBSpringAnimation I noticed that movement was quite jerky in the initial phases of the spring animation.

To combat this I increased the "sampling rate" specified in RBBAnimation's values method from 60 to 120. Eg:

- (NSArray *)values {
    RBBAnimationBlock block = [self.animationBlock copy];

    CFTimeInterval duration = self.duration;

    return [RBBBlockBasedArray arrayWithCount:(NSUInteger)(duration * 120) block:^id(NSUInteger idx) {
        return block(idx / 120.0f, (CGFloat)duration);
    }];
}

The results seem to be smoother animations.

I'm not a math/signal processing whiz but I think this is an example of the Nyquist rate.

Perhaps this could be made a property on RBBSpringAnimation. As in some situations I think 60 would be fine but others a higher value is going to produce smoother results.

@robb robb added the bug label Jul 1, 2015
@robb
Copy link
Owner

robb commented Jul 1, 2015

That explanation seems reasonable to me, thanks 💖

Do you happen to have an example project at hand that shows an example of this behavior?

@orj
Copy link
Author

orj commented Jul 1, 2015

I just hacked together a sample but I can't attach to issue (because Github doesn't support zips). I'll throw it in a git repo.

With this sample I think I also ran into another solution to the smoothness issue. Changing the calculation mode to linear from discrete.

@orj
Copy link
Author

orj commented Jul 1, 2015

I've pushed up a sample to https://github.com/orj/RBBAnimation-SmootherSpring

The sample lets you control the animation with the slider. Once the app loads into the iOS simulator hit the "setup" button then you can control the time with the slider. You will see a default of 60 leads to big jumps at the beginning of the animation for the red box but the blue box is smoother with 120 keyframes.

Set the segmented control to linear and hit setup again to see how kCAAnimationLinear calculationMode effects the animation.

@orj
Copy link
Author

orj commented Jul 1, 2015

Oh, to get it to build don't forget to git submodule update --init --recursive in the clone of my repo to pull down your animation lib as a submodule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants