UIView の数が事前に定義されていない場合、複数の UIView が重複しないようにするにはどうすればよいですか? 特定のパディング定義が満たされている限り、画面上のどこに配置されるかはあまり気にしません。
autolayout を使用する方法のようですが、うまくいきません。
おそらくループが必要になるでしょう
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