【发布时间】:2012-06-04 19:15:56
【问题描述】:
嘿,伙计们,我一直在制作一个游戏,其中用户按下一个按钮,每次按下该按钮时,屏幕都会添加一个新的 UIImageView(每次都相同)。这些 UIImageView 可以通过 UITouch 功能单独拖动。但我希望他们也能检测到十字路口! 我想知道哪两个 UIImageViews 相交,这样我就可以更改相交的两个 UIImageViews 的 image-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";
}
}
我希望这是足够的信息来帮助我!
【问题讨论】: