在我的应用程序中,我有许多 UIButtons 动态添加到视图中,我使用下面的方法在视图周围拖动它们。
//forDragAction
[btnTarget addTarget:self action:@selector(wasDragged:withEvent:)
forControlEvents:UIControlEventTouchDragInside];
- (void)wasDragged:(UIButton *)button withEvent:(UIEvent *)event
{
// get the touch
UITouch *touch = [[event touchesForView:button] anyObject];
// get delta
CGPoint previousLocation = [touch previousLocationInView:button];
// frameof buttonChanged here
}
如果拖动的一个与任何其他相交,我想停止拖动动作,我知道我可以使用for
如下循环来检查是否有任何 UIButton 正在交互
for(UIButton *btn in [[button superview] subViews])
{
//check if the btn frame interact with any others if so comeout of loop
}
我想知道是否有其他方法,如前所述,如果 subViews 计数增加到如此之多,方法会变慢
编辑:- UIButtons 被动态添加到 UIView (但子视图的总数不会超过 120)