2011-02-02 134 views
2

我正在使用UIPanGesture返回velocityInView,并且从我收集的数据中推测它应该是每秒返回的点数。我得到的数字是数亿和很多零......我没有在模拟器中快速移动我的鼠标。iOS - 使UIPanGesture上的velocityInView有意义

我认为...

在此先感谢您的任何帮助/建议。

编辑:请求代码。

显示/呼叫

-(void)handlePanGesture:(UIPanGestureRecognizer *) recognizer 
{ 
    if (recognizer.state == UIGestureRecognizerStateChanged || 
     recognizer.state == UIGestureRecognizerStateBegan) 
    { 
     CGPoint vel = [recognizer velocityInView:myScrollView]; 
     //[self doSpinAnimationWithVelocity:vel.x]; 
     NSLog([NSString stringWithFormat:@"Velocity - X-Axis - %d ", vel.x]); 
     NSLog([NSString stringWithFormat:@"Velocity - Y-Axis - %d ", vel.y]); 
    } 
} 

Image here of output since I'm still below 10 rep

+0

如果它有所作为,我现在只捕获x轴。 – Mytheral 2011-02-02 19:27:10

+0

y轴也给出了类似的信息。 – Mytheral 2011-02-02 19:28:59

+0

显示您调用velocityInView的代码以及您如何显示数字。 – Anna 2011-02-02 19:35:07

回答

4

没有你的代码很难说......

CGPoint由CGFloats,这取决于你如何打印它们,你可以获得意想不到的结果

您传入velocityInView的视图:必须位于视图层次结构中,通过查看窗口属性,然后再将它传递给velocityInView:方法

0

它看起来像velocityInView:返回一个CGPoint,代表水平和垂直分量(基本上,它是一个向量)。由于速度分解为这两个分量,所以您必须小心如何分析这些值。如果您寻找更多的速度,而不是速度,你会采取的矢量的幅值,即是这样的:

CGFloat magnitude = sqrtf((velocityPoint.x * velocityPoint.x) + (velocityPoint.y * velocityPoint.y)); 
1

我知道我有点迟到了,但是还有一个小窍门:退房NSStringFromCGPoint( )和家族:

-(void)handlePanGesture:(UIPanGestureRecognizer *) recognizer 
{ 
    if (recognizer.state == UIGestureRecognizerStateChanged || 
     recognizer.state == UIGestureRecognizerStateBegan) 
    { 
     CGPoint vel = [recognizer velocityInView:myScrollView]; 
     NSLog(@"%@", NSStringFromCGPoint(vel)); 
    } 
}