我想使用UIPushBehavior为屏幕上的视图提供逼真的物理动画。但要做到这一点,我需要能够在UIPushBehavior的pushDirection属性中计算出CGVector中所需的推力大小。
基本上,我知道视图的大小,时间量,以及我希望它移动的距离。有没有一种方法可以使用UIKit牛顿定义和带有阻力的UIDynamicItemBehavior来精确计算在特定时间内将视图移动特定距离所需的大小?
发布于 2016-02-14 17:01:47
如果你使用的是平移手势,你可以这样做:
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;
}由Tony Dahbura's tutorial提供。
https://stackoverflow.com/questions/21812121
复制相似问题