我们正在添加拖放功能,以便成为一个有球员位置的运动场.
使用Interface Builder映射出位置,每个位置都是一个单独的UIImageView.
我们希望能够将玩家图像从屏幕一侧的工作台位置拖动到场地上的位置.
我们如何最好地检测被移动的所选玩家何时与现有的gamePosition imageView碰撞?
我们正在寻找一种方法来检测当前位置下是否存在视图或ImageView.
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
tile1.center = location;
if gamePositionExistsAtCurrentLocation(location) { //want something like this
[tile1 setBackgroundColor:[UIColor blueColor]];
} else {
[tile1 setBackgroundColor:[UIColor yellowColor]];
}
}
Run Code Online (Sandbox Code Playgroud)