facebookarchive / pop

An extensible iOS and OS X animation library, useful for physics-based interactions.
Other
19.66k stars 2.88k forks source link

Running POPSpringAnimation at the same time as keyboard animation causes stutter #257

Closed tettoffensive closed 9 years ago

tettoffensive commented 9 years ago

I have a UIView which the layer is animating both bounds and position. Ideally, I'd like it to run at the same time as the keyboard animating up when I call becomeFirstResponder. However, this causes the pop animation to "stutter" and not be smooth.

I'm not sure what the best practice is for this currently? For now, I'll have to wait to call the keyboard, which doesn't look as nice.

POPSpringAnimation *boundsAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
boundsAnimation.toValue = [NSValue valueWithCGRect:_popoverViewFeedback.layer.bounds];
boundsAnimation.springBounciness = 5.f;
boundsAnimation.springSpeed = 20.;
boundsAnimation.dynamicsMass = 2.;
boundsAnimation.dynamicsTension *= 1.5;
boundsAnimation.beginTime = CACurrentMediaTime() + 0.01;

POPSpringAnimation *positionAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPosition];
positionAnimation.toValue  = [NSValue valueWithCGPoint:_popoverViewFeedback.layer.position];
positionAnimation.springBounciness = boundsAnimation.springBounciness;
positionAnimation.springSpeed      = boundsAnimation.springSpeed;
positionAnimation.dynamicsMass     = boundsAnimation.dynamicsMass;
positionAnimation.dynamicsTension  = boundsAnimation.dynamicsTension;
positionAnimation.beginTime        = boundsAnimation.beginTime;

[_textView becomeFirstResponder];
[_popoverView.layer pop_addAnimation:boundsAnimation forKey:@"layerPopoverBoundsSpringAnimation"];
[_popoverView.layer pop_addAnimation:positionAnimation forKey:@"layerPopoverPositionSpringAnimation"];
grp commented 9 years ago

There isn't really a good solution: if you have something blocking the main thread (like the first time you show a keyboard usually does), then Pop's animations can't run. The general advice is to avoid blocking the main thread as much as you can, but as you said that's hard when it's a system component.

I don't think there's much Pop can do about this, unfortunately. You might file a radar to see if this could be improved in a future update...