我想用UIPushBehavior
来提供屏幕上视图的物理逼真的动画。但要做到这一点,我需要能够计算UIPushBehavior
pushDirection
属性中CGVector
所需的推力大小。
基本上,我知道视图的大小,时间量以及我希望它行进的距离。有没有办法使用UIKit
牛顿定义和带电阻的UIDynamicItemBehavior
来准确计算在特定时间内将视图移动特定距离所需的幅度?
如果您使用的是平移手势,则可以执行以下操作:
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的教程提供。