こんにちは、私はユーザーがボタンを押すゲームを作成しており、そのボタンを押すたびに、画面に新しい UIImageView が追加されます (これは毎回同じです)。これらの UIImageView は、UITouch 関数を使用して個別にドラッグできます。しかし、交差点も検出してほしいです!そして、どの2つのUIImageViewが交差したかを知りたいので、交差する2つのUIImageViewの画像URLを変更できます。
-(IBAction)ClTouched:(id)sender {
imgView2 = [[UIImageView alloc] initWithFrame:CGRectMake(120, 20, 80, 80)];
imgView2.backgroundColor = [UIColor clearColor];
imgView2.userInteractionEnabled = TRUE;
imgView2.image = [UIImage imageNamed:@"Cl.png"];
[self.view addSubview:imgView2];
}
// タッチで画像を移動するには - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { imgView.userInteractionEnabled = TRUE;
// get touch event
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if ([self.view.subviews containsObject:[touch view]]) {
[touch view].center = touchLocation;
}
if (CGRectIntersectsRect(imgView.frame, imgView2.frame)) {
naam.text = @"INTERSECTION";
}
}
これが私を助けるのに十分な情報であることを願っています!