Masonry
Masonry copied to clipboard
mas_commonSuperviewOfViews not work proper
New Issue Checklist
🚫 If this template is not filled out your issue will be closed with no comment. 🚫
- [x] I have looked at the Documentation
- [x] 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.