Im trying to understand how the UIDynamicAnimator
calculates the values each iteration.
For example i have a simpel exampel where i have a UIAttachmentBehavior
and a UIDynamicItemBehavior
attached to the same DynamicItem
UIAttachmentBehavior *attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:test attachedToAnchor:CGPointMake(50, 50)];
attachmentBehavior.frequency = 3.5;
attachmentBehavior.damping = .4;
UIDynamicItemBehavior *dynamicItemBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[test]];
dynamicItemBehavior.resistance = 10;
dynamicItemBehavior.action = ^{
NSLog(@"%f", [dynamicItemBehavior linearVelocityForItem:test]);
};
Whenever i change the anchorPoint of the UIAttachmentBehavior
it will animate to that location with a spring animation.
I dont understand how the DynamicItemBehavior
knows about this movement, and thereby can apply its physics properties (resistance, density etc) to the movement triggered by a different Behavior?
Does the UIDynamicAnimator
somehow prioritise and accumulate the values from all the behaviors (velocity, damping etc).
in my head it does something like
var velocity;
for behavior in item.behaviors
velocity += behavior.velocity * behavior.damping
item.position = delta_time * velocity