touchesMoved事件没有得到正确的CGPoint

时间:2014-04-26 07:09:04

标签: ios objective-c

我试图通过设置 bounds 来实现scrollView,同时显示视图 我正在touchesMoved进行测试:

UITouch* touch = [touches anyObject];
CGPoint pt = [touch locationInView:self];
if(pt.x - _lastPoint.x >= 0){
    NSLog(@"yep");
}
else{
    NSLog(@"nope");
    NSLog(@"%f",pt.x);
}
_lastPoint.x = pt.x;
[self setBounds:CGRectMake(self.bounds.origin.x - 1, 0,  self.frame.size.width, self.frame.size.height)];

当我朝一个方向(从左到右一直)呻吟时,我总能得到一些坏点,这是其中一个日志:

2014-04-26 14:59:41.621 LScrollView[9884:60b] yep
2014-04-26 14:59:41.638 LScrollView[9884:60b] yep
2014-04-26 14:59:41.656 LScrollView[9884:60b] yep
2014-04-26 14:59:41.673 LScrollView[9884:60b] yep
2014-04-26 14:59:41.696 LScrollView[9884:60b] yep
2014-04-26 14:59:41.713 LScrollView[9884:60b] yep
2014-04-26 14:59:41.729 LScrollView[9884:60b] yep
2014-04-26 14:59:41.762 LScrollView[9884:60b] yep
2014-04-26 14:59:41.796 LScrollView[9884:60b] nope
2014-04-26 14:59:41.797 LScrollView[9884:60b] 143.000000
2014-04-26 14:59:41.813 LScrollView[9884:60b] yep
2014-04-26 14:59:41.829 LScrollView[9884:60b] yep
2014-04-26 14:59:41.846 LScrollView[9884:60b] yep

我还写了一个测试,更改touchesMoved中视图的界限,一切正常,我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

当您在其上拖动手指时,无需更改视图的边界。你总是在左侧将原点设为1像素。我的意思是如果它在下一个事件的x = 0时它将被转移到x = -1。

直到生成下一个事件并且您没有向正确方向拖动手指1个像素的时间,应用程序将返回无法满足您的if条件的点。因此,在每个拖动事件中删除setBounds或快速拖动手指。