gpt4 book ai didi

ios7 - UIKit 动态 : Calculating pushDirection Needed for UIPushBehavior

转载 作者:行者123 更新时间:2023-12-02 20:33:46 26 4
gpt4 key购买 nike

我想使用 UIPushBehavior 为屏幕上的 View 提供物理逼真的动画。但要做到这一点,我需要能够计算 UIPushBehaviorpushDirection 属性中的 CGVector 所需的推力大小。

基本上,我知道 View 的大小、时间量以及我希望它移动的距离。有没有办法使用 UIKit Newton 定义和具有阻力的 UIDynamicItemBehavior 来准确计算在特定时间内将 View 移动特定距离所需的幅度?

最佳答案

如果您使用平移手势,则可以执行以下操作:

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 提供.

关于ios7 - UIKit 动态 : Calculating pushDirection Needed for UIPushBehavior,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21812121/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com