关于TouchesMoved的一些奇怪之处

时间:2013-04-05 04:30:18

标签: objective-c xcode

我只想输出每次触摸的坐标。 这是代码:

- (void)drawRect:(CGRect)rect
{
    [[UIColor blackColor] set];
    for (int i = 0; i<_touches.count; i++){
        CGPoint pos=[[_touches objectAtIndex:i] locationInView:self];
        NSString* str = [NSString stringWithFormat:@" %d:(%d,%d)",i+1,(int)pos.x, (int)pos.y];
        [str drawAtPoint:CGPointMake(0,16+16*i) withFont:font];
    }
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSArray* objects = [touches allObjects];
    for (int i=0;i<objects.count;i++){
        [_touches addObject:[objects objectAtIndex:i]];
    }
    [self setNeedsDisplay];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    [self setNeedsDisplay];
}

它有效。 输出如下: 1:(20,50) 2:(30,69) ... 但问题是,每次我在屏幕上拖动, 拖动时,最新触摸的坐标正在变化。 我相信touchesMoved对存储每个触摸坐标的_touches没有任何影响,因此移动(拖动)时最新坐标不应该改变。 任何帮助表示赞赏。 非常感谢。

0 个答案:

没有答案