【发布时间】:2012-03-07 12:52:28
【问题描述】:
在我的应用程序中,我的头文件有五个不同的 UIImageViews,需要放置在另外五个固定的 UIImageViews 上。
所以五个永远不会移动,五个用户放在静止的上面。固定的在一个名为 posArray 的数组中,而其他可移动的五个也在一个数组中。
所以现在用户去触摸可移动的并将它们拖到静态的上。如果可移动对象与静态对象发生碰撞,则可移动对象的 x,y 变为静态对象的 x,y。
我的问题是如何判断哪个可移动物体正在接触哪个静态物体?
movableObj1 是接触 staticObj1 还是 staticObj2 还是哪一个?可移动的可以放在任何地方,所以我不知道一旦它们接触到它们的名字。
下面的代码是使可移动数组在它们接触时粘在静态数组上的原因。可移动对象可以放置在五个静态对象中的任何一个中。
for (int i = 0; i < [posArray count]; i++) {
UIImageView *tempPos;
tempPos = [posArray objectAtIndex:i];
if (CGRectIntersectsRect(tempPlayer.frame, tempPos.frame)) {
tempPlayer.center = CGPointMake(tempPos.center.x, tempPos.center.y);
}
}
【问题讨论】:
-
可以为每个UIImageview设置标签。
标签: iphone xcode object properties