How to detect a common superview.
Anoniem
- (nullable UIView *)commonSuperview:(nullable UIView *)otherView { if(!otherView) return nil; NSMutableArray* superViewsArray = [NSMutableArray array]; UIView* superVeiw = self; while (superVeiw) { [superViewsArray addObject:superVeiw]; superVeiw = superVeiw.superview; } superVeiw = otherView; while (superVeiw) { if([superViewsArray containsObject:superVeiw]){ break; } superVeiw = superVeiw.superview; } return superVeiw; }