-1

シンプルなグリッドのアプリがあります。(各グリッド空間の中心点をNSValue含む の配列があります。)CGPoint

ユーザーは画面のどこにでも触れることができます。ユーザーが触れる場所に最も近いグリッド スペースを見つける方法を知りたいです。

4

2 に答える 2

1

ピタゴラスの定理を使用します。ポイントまでの距離 = sqrt((p2.x - p1.x)^2 + (p2.y - p1.y)^2)。p1 が接触点である場合、この方程式を使用して、p2 をグリッド上の各点とし、最大距離を見つけます。

于 2013-08-25T22:27:12.520 に答える
-2

これを行うには、以下の方法を使用できます。

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {<br>
        id hitView = [self hitTest:currentTouchPoint withEvent:event];<br>
        if ([hitView isKindOfClass:[RDWord class]]) { // basically find the type of view you  
                                                       // want over here                              
        }

}

または、以下のように使用できます。

UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
UIView *hitView = [self hitTest:location withEvent:event];
于 2013-08-25T19:24:40.877 に答える