2011-05-06 52 views
1

這是我的測試代碼touchesBegin,touchesMoved和anyObject問題

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 
    gestureStartPoint = [touch locationInView:self.view]; 
    NSLog(@"start (%f, %f)", gestureStartPoint.x, gestureStartPoint.y); 
} 
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 
    CGPoint currentPosition = [touch locationInView:self.view]; 
    NSLog(@"move (%f, %f)", currentPosition.x, currentPosition.y); 
} 

從我的理解[觸摸anyObject]將返回任何對象(任何指的是觸摸屏),所以我開始在我的測試中模擬的選項+重複點擊屏幕,結果是我期望的x,y點從一個到另一個隨機變化。 我的問題是觸摸移動後,我用兩根手指觸摸移動(選項+單擊)我開始拖動和預期x,y會像touchesBegan一樣隨機改變,但結果令我驚訝,x,y將是相同的co-or)就像我從touchesBegan那裏得到的那樣。

所以這種行爲有解釋的地方?

+0

這是一個敏感的帖子。 – pixelbobby 2011-05-06 17:03:53

回答

1

來源:NSSet Class Reference

- (id)anyObject 

返回值
一個在 對象的集合,或者零如果集合不包含 對象。返回的對象在方便的情況下選擇 - 選擇 不保證是隨機的。

我認爲在內部,他們被關在順序(或生成基於座標),並加入到集秩序,它只是方便了一套給他們你的順序