【发布时间】:2012-10-24 02:29:51
【问题描述】:
给定一个可以拖动视图的视图层次结构,检测被拖动视图与其他视图之间的冲突的最有效方法是什么?
这将是蛮力方法(在伪代码中):
- (void) onDrag
{
CGRect absoluteDraggedViewRect; // Calculate
for (UIView *otherView in hierarchy)
{
CGRect absoluteOtherViewRect; // Calculate
if (CGRectIntersectsRect(absoluteDraggedViewRect, absoluteOtherViewRect))
{
// Collision!
}
}
}
你会如何改进上面的代码?
【问题讨论】:
标签: iphone ios uiview draggable collision-detection