UIKit dynamics: calculating pushDirection for UIPushBehavior

I would like to use UIPushBehaviorto give a physically realistic animation of the view across the screen. But for this I need to be able to calculate the amount of depression required in CGVectorthe property pushDirection UIPushBehavior.

Basically, I know the size of the view, the amount of time and the distance that I would like to travel. Is there a way to use the definition of UIKitNewton and a UIDynamicItemBehaviorwith resistance to accurately calculate the amount needed to move the vision a certain distance over a certain period of time?

+3
source share
1 answer

If you use a panorama gesture, you can do this:

if ( gestureRecognizer.state == UIGestureRecognizerStateEnded )
{
     CGPoint velocity = [gestureRecognizer velocityInView:gestureRecognizer.view.superview];
     CGFloat magnitude = sqrtf((velocity.x * velocity.x) + (velocity.y * velocity.y));

     myPushBehavior = [[UIPushBehavior alloc] initWithItems:@[gestureRecognizer.view]
                                                         mode:UIPushBehaviorModeInstantaneous];
     myPushBehavior.pushDirection = CGVectorMake((velocity.x / 10) , (velocity.y / 10));
     myPushBehavior.magnitude = magnitude;
}

.

0

All Articles