如果事先未定义 UIView 的数量,如何防止多个 UIView 重叠?只要满足特定的填充定义,我真的不在乎它们在屏幕上的位置。
使用自动布局似乎是这样做的方法,但我做不到。
我可能需要一个循环
UIView *prevView = nil;
for (UIView *aView in [self subViews])
{
// would really need to check foreach subview if this view isn't overlapping
// lets assume just 2 views for simplicity
if (CGRectIntersectsRect(aView.frame,prevView.frame))
{
// update the view frame
// or update autolayout constraints
}
}
// might need to call the function recursively if first pass wasn't successful