【发布时间】:2011-04-26 05:20:25
【问题描述】:
我们正在为即将成为具有球员位置的运动场添加拖放功能。
使用 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]];
}
}
【问题讨论】:
标签: iphone drag-and-drop ios collision-detection