1

既知の場所 (CGPoint) があり、ビュー自体、その中のボタン、ラベル、その他のインスタンスのいずれであっても、その下またはそれを含むオブジェクトのビュー (UIView) をクエリしたい

次に、そのオブジェクトを取得し、その型を調べて、ユーザーがタップしたときに発生するメソッドを呼び出します。

ビューで touchesBegan を呼び出してみましたが、タッチ イベントまたは uievents を作成する方法がないようです...間違っている場合は修正してください。

hitTest でこれを行う方法があるのではないかと考えていますが、確信が持てません。

4

1 に答える 1

0

ヒットテストはそれを行います。

何かを返したくない場合は、userInteractionEnabled をオフにします

        //Send touch down event

        //Now, this is a bit hacky. Theres no public contrustors for UITouch or UIEvent, thus calling touches*: on the view is not possible. Instead, I search the view underneath it (with Hit Test) and call actions on that. 

        //Note. You need to allow for each type of object below, for the scope of the demo, I've allowed for only UIView and UIButton.

        UIView *v = [[self view] hitTest:pointer.frame.origin withEvent:nil]; //origin is top left, point of pointer. 

        NSLog(@"%@", [v class] );

        if([v isKindOfClass:[UIButton class]]){
            selectedButton = (UIButton *)v;

        }
        else if ([v isKindOfClass:[UIView class]] && [[v backgroundColor] isEqual:[UIColor redColor]]){
            selectedView = v;
            dragLabel.text = @"You are dragging me!";
            dragPoint = pointer.frame.origin; //record this point for later. 

        }
        else {
            NSLog (@"touched but no button underneath it");
        }
于 2012-08-21T19:39:36.840 に答える