8

オブジェクトの交差の検出に問題がありUIViewます。

それが私が以下で使用したものです:

交差点 2 オブジェクトの場合、1 つの座標系を最初のスーパービューから別の座標系に変換する方法を理解する必要があります。

私はこのアプローチを使用しました:- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)viewここで説明されていますリンク.

私が知っているように、この方法を使用するのは非常に簡単です。しかし、さまざまなケースでは、ドキュメントに少し説明があるため難しいです (しかし、おそらく私にとっては)。

これは、下の画像に示されているサブビューの私の構造です。オブジェクトをドラッグアンドドロップするためのすべてのメソッドを既に取得しています。UIView しかし、 AUIView Bの交点を取得する方法を理解する必要があります。手伝ってくれてありがとう。

ここに画像の説明を入力

4

2 に答える 2

5

このソリューションを実装しました:

- (void)putComponent:(NSNotification *)notif {
    // Catch B UIView.
    UIView *view = [notif object];
    // Convertation. [self superview] - is view wher A UIView is placed.
    CGRect convertedRect = [[self superview] convertRect:view.frame fromView:[view superview]];
    // Find center point.
    CGPoint point;
    point.x = convertedRect.origin.x + (convertedRect.size.width / 2.0f);
    point.y = convertedRect.origin.y + (convertedRect.size.height / 2.0f);
    // Find if CGRect (self.frame) contains a point (center of B UIView)
    BOOL contains = CGRectContainsPoint(self.frame, point);
    if (contains) {
        NSLog(@"intersect here");
    }
}
于 2012-12-20T20:54:36.000 に答える