【问题标题】:How to make dragging faster using velocityView in UIPanGestureRecognizer?如何在 UIPanGestureRecognizer 中使用 velocityView 加快拖动速度?
【发布时间】:2011-08-04 06:15:54
【问题描述】:

在理解如何为我在下面使用的代码(由@PaulSoltz 编写)实现更快的拖动速度时遇到了一些麻烦,它允许您在屏幕上拖动对象。我意识到你必须使用UIPanGestureRecognizer 中的velocityInView 方法,我知道它返回x 速度向量和y 速度向量。如果速度 = 随时间变化的距离,那么例如 velocityx = (x2 - x1) / time 我不确定如何使用这个公式来获得我需要的东西。基本上我只是希望能够调整我的运动速度以使其更快一点。也许我想太多了,但是如果有人可以帮助我理解这一点,将不胜感激。谢谢。

- (void)handlePanGesture:(UIPanGestureRecognizer *)gestureRecognizer {

    UIView *myView = [gestureRecognizer view];

    CGPoint translate = [gestureRecognizer translationInView:[myView superview]];


    if ([gestureRecognizer state] == UIGestureRecognizerStateChanged || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
        [myView setCenter:CGPointMake(myView.center.x + translate.x, myView.center.y + translate.y)];
    [gestureRecognizer setTranslation:CGPointZero inView:[myView superview]];
    }
}

【问题讨论】:

    标签: iphone ios cocoa-touch core-graphics uigesturerecognizer


    【解决方案1】:

    只需将平移向量的分量乘以某个常数即可。

    [myView setCenter:CGPointMake(myView.center.x + translate.x * 2, myView.center.y + translate.y * 2)];
    

    【讨论】:

    • 好的,velocityView 会跟踪您拖动对象的速度有多快或多慢,如果您想让它在任何类型的拖动中保持恒定速度,您只需乘以某个常数?有道理……
    • 这可以完成这项工作,但它使图像移动的速度比您的手指在它上面移动的速度更快,这使它看起来很有趣。我实际上不认为有办法让它移动得更快而不这样做,因为这完全取决于你的手指速度。
    猜你喜欢
    • 2013-01-07
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    • 2010-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多