You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently, I read the source code of Snapkit and Masonry, I find that Snapkit doesn't check two views's commonSuperview, but instead, Masonry has this func, why?
The text was updated successfully, but these errors were encountered:
Not sure why SnapKit doesn't have the closestCommonSuperview function - but nonetheless you can always build your own solution. Here's a closestCommonSuperview function I created without using any 3rd party libraries. Hope that helps!
func fetchClosestCommonSuperView(_ lhs: UIView, _ rhs: UIView) -> UIView? {
var leftSuperViews: [UIView] = []
var currentSuperView = lhs.superview
while let superView = currentSuperView {
leftSuperViews.append(superView)
currentSuperView = currentSuperView?.superview
}
currentSuperView = rhs.superview
while let superView = currentSuperView {
if leftSuperViews.contains(superView) {
return superView
}
currentSuperView = currentSuperView?.superview
}
return nil
}
Recently, I read the source code of Snapkit and Masonry, I find that Snapkit doesn't check two views's commonSuperview, but instead, Masonry has this func, why?
The text was updated successfully, but these errors were encountered: