SnapKit / Masonry

Harness the power of AutoLayout NSLayoutConstraints with a simplified, chainable and expressive syntax. Supports iOS and OSX Auto Layout

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mas_commonSuperviewOfViews not work proper

dylanNew opened this issue Β· comments

New Issue Checklist

🚫 If this template is not filled out your issue will be closed with no comment. 🚫

  • I have looked at the Documentation
  • I have filled out this issue template.

Issue Info

Info Value
Platform ios/osx/tvos
Platform Version 8.0
Masonry Version e.g. 1.1.0
Integration Method cocoapods

Issue Description

NSArray+MASAdditions.m

- (MAS_VIEW *)mas_commonSuperviewOfViews
{
    MAS_VIEW *commonSuperview = nil;
    MAS_VIEW *previousView = nil;
    for (id object in self) {
        if ([object isKindOfClass:[MAS_VIEW class]]) {
            MAS_VIEW *view = (MAS_VIEW *)object;
            if (previousView) {
                commonSuperview = [view mas_closestCommonSuperview:commonSuperview];
            } else {
                commonSuperview = view;
            }
            previousView = view;
        }
    }
    NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy.");
    return commonSuperview;
}

and I have created some views like this:

UIView *a = [UIView new];
UIView *b = [UIView new];
UIView *c = [UIView new];
UIView *d = [UIView new];
UIView *e = [UIView new];
[a addSubview:b];
[a addSubview:c];
[b addSubview:d];
[b addSubview:e];

[@[b,d,e] mas_commonSuperviewOfViews];   // this will return view "b"
[@[d,e,b] mas_commonSuperviewOfViews];  // this will return view "a"

From code, it just will return last two views common superview. Hope can fix this.