Is it possible to pause UIDynamicAnimator without deleting and adding UIDynamicBehaviours?

I am implementing some animations using UIDynamics to enable some transitions between representations based on physics. I would like to pause and continue these animations programmatically in response to user touch. The only way I've found this so far is to remove the dynamic animator behavior and then re-add them as follows:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.dynamicAnimator removeBehaviour: self.behaviour1]; [self.dynamicAnimator removeBehaviour: self.behaviour2]; // etc } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { self.behaviour1 = [[UIGravityBehavior alloc] initWithItems: @[self.item]]; self.behaviour1.gravityDirection = self.gravityVector; [self.dynamicAnimator addBehaviour: self.behaviour1]; self.behaviour2 = [[UICollisionBehavior alloc] initWithItems: @[self.item]]; [self.behaviour2 addBoundaryWithIdentifier: @"Boundary" forPath: self.boundary]; [self.dynamicAnimator addBehaviour: self.behaviour2]; // etc } 

(Beyond this: I also used [self.dynamicAnimator updateItemUsingCurrentState: item] instead of re-creating the behavior, but I still have to remove them from the dynamic animator and add them again to pause while the user touches the screen.)

What I would like to do is self.dynamicAnimator.running = NO suspend, and then self.dynamicAnimator.running = YES continue. This would be far ahead, using less code (I currently have five behaviors), and this will help to avoid possible errors in this process. Unfortunately, the dynamicAnimator.running property is read-only, so this is not possible.

Is there a way to pause and continue the UIDynamicAnimator in a row or two that I missed?

+6
source share

All Articles