我試圖創造一個當我點擊在大致相同的位置,我的最後一個觸摸結束,其中一個程序,一個圓圈會改變顏色。我用用邏輯沿的線條previousLocationInView方法的嘗試:「如果的touchesBegan位置== previousTouchesLocation,改變顏色爲藍色。」此方法不起作用,因爲的touchesBegan和previousTouchLocation座標有它總是改變而不管位置如何,每當我點擊屏幕顏色相同的值。如果我用touchesEnded替換previousTouchLocation,我會得到相同的結果。如果有人認爲它可以提供幫助,這裏是代碼。是否有可能根據水龍頭的位置創建一個水龍頭?
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch* touch = [touches anyObject];
touchLocation = [touch locationInView:self.view];
lastTouchLocation = [[touches anyObject] previousLocationInView:self.view];
distance_x = touchLocation.x - cvx;
distance_y = cvy - touchLocation.y;
previousDistance_x = lastTouchLocation.x - cvx;
previousDistance_y = cvy - lastTouchLocation.y;
if ((previousDistance_x == distance_x) && (previousDistance_y == distance_y)) {
if (([cv.color isEqual:[UIColor redColor]])) {
[cv setColor:[UIColor blueColor]];
}
else
[cv setColor:[UIColor redColor]];
}
}
謝謝!這正是我需要的。我遵循你的建議(創建了一個伊娃),現在我的程序正是按照我希望的方式工作的! – user2379694