POP + AsyncDisplayKit
What is the standard was of working with POP and AsyncDisplayKit? If a node's frame changes, the parent's node calls layout() again. If layout() sets up all the frames, then nothing will ever animate because the animated frame will keep being reset.
Should the node expose a property that updates the node's frame, along with another property value that layout() will read to change the position? Or is there a better approach?
The only project I've seen that uses POP and AsyncDisplayKit, actually has a flag that makes layout() only run once.
I would love to learn more about this as well. When I try to use a POP animation on a node's layer I hit an assertion in ASDisplayNode+UIViewBridge.mm stating Must be an identity transform. Is there a way to perform a non-identity transform? Confused at how to use POP with AsyncDisplayKit if this assertion is the case.
When I try to use a POP animation on a node's layer I hit an assertion in ASDisplayNode+UIViewBridge.mm stating
Must be an identity transform. Is there a way to perform a non-identity transform?
This is because you're trying to use the frame and transform properties — frame is a derived property, and it's undefined for non-identity transforms. If you try using them both with UIView directly, your app won't crash but its animations will glitch; since this is never correct behaviour, AsyncDisplayKit warns you with an assert in DEBUG builds.
Some relevant Apple documentation:
Changes to this property can be animated. However, if the
transformproperty contains a non-identity transform, the value of theframeproperty is undefined and should not be modified. In that case, you can reposition the view using thecenterproperty and adjust the size using theboundsproperty instead.
For layers, the
framerectangle is a computed property that is derived from the values in thebounds,anchorPointandpositionproperties. When you assign a new value to this property, the layer changes itspositionandboundsproperties to match the rectangle you specified.
So, if you need to use transform, set bounds and center (or bounds, position, and anchorPoint) instead of frame and everything will work. =]
Any of you guys had any luck animating the bounds with POP?
Yes! @secretiverhyme's suggestion was perfect. By setting the bounds and position of a node, I had no trouble animating it.
@1nput0utput - are you still having issues?
@ajk198, back to your issue:
If a node's frame changes, the parent's node calls layout() again. If layout() sets up all the frames, then nothing will ever animate because the animated frame will keep being reset.
I am experiencing the same, and solved using the following method:
- In
viewWillLayoutSubviews, where the node frame is set, wrap the layout code in an if statement that checks if the node has an animation:
if myView.pop_animationForKey(kCardAnimationKey) == nil {
//do layout code here, be sure to use the same frame you calculated to be set on the animation.
}
This resolved my issue. One thing is that once the animation is complete, the if statement will execute and your node will receive a setFrame call, which is why it's important to make sure the frame matches the toValue you used when setting up your animation
For further reference, I used POPSpringAnimation(propertyNamed: kPOPViewFrame) and applied it directly to my ASDisplayNode subclass
Yup
Awesome tips shared here. Yes, animating with bounds and position should be preferred — in part because it is /absolutely necessary/ if you ever use a non-identity transform (scale, rotate, anything). The documentation that Nadine linked to is the key reference there.
For what it's worth, using ASDK with Pop is essentially the same as using UIKit with Pop — in terms of how you structure the animation and layout code. However, there's a brilliant synergy between the two frameworks, because Pop (and UIKit Dynamics / any physics-simulating animation system) is very very sensitive to stalls on the main thread. Check out my NSLondon talk for some discussion of this: https://www.youtube.com/watch?v=h4QDbgB7RLo
@ajk198 @mmoutenot @OneMe2015 @1nput0utput please feel free to post a new task, or post to our AsyncDisplayKit Google Group, if you have any further questions here. There's also the Pop project for more animation-specific questions.
hey guys, i'm looking for the right approach to adding an appear animation to a subnode in my ASCellNode whenever a cell appears on screen. Tried a bunch of different things (layoutDidFinish on the node, willDisplayNode: on the tableView delegate, and a couple other things). Feel free to point me in the direction of the docs or a sample if that's easiest!
@adcooley hey, just happened to see this — feel free to file a new issue if you haven't found an approach yet, and it's still relevant to you. Answers could vary depending on whether you're using physics-simulating animations or UIView / CA animations, but most importantly, it depends on what part of the cell you're animating (the entire thing? elements within it? is it possible they may not have loaded from the network yet and need to animate when they're done? etc)
@appleguy, I'll bite on the above since I'm trying to accomplish what sounds like a very similar thing. What I'm trying to do is create a subnode within an ASCellNode (with ASTableView) which holds an image placeholder at first (with a preferredFrameSize set to 200 height, say), then when the image finishes downloading I would like to:
- the placeholder should animate to the right height based on the image received, then
- The image should grow from the center and use a pop animation to 'spring' into the placeholder from the center (a grow effect)
Right now in an attempt to get 1. working I am using the technique discussed in #718 to update layout, but what happens is that the image gets inserted first instantaneously, _and then everything scoots down to fit it, but things are hidden behind the image in the transient state. 2 above I haven't even attempted yet as a result, but if you had any thoughts/issues/sample code you think would be helpful on one or both, it would be much appreciated!