Ejemplo n.º 1
0
        internal static UIView ClosestCommonAncestror(UIView a, UIView b)
        {
            var aSuper = a.Superview;
            var bSuper = b.Superview;

            if (ReferenceEquals(a, b))
            {
                return(a);
            }
            if (ReferenceEquals(a, bSuper))
            {
                return(a);
            }
            if (ReferenceEquals(b, aSuper))
            {
                return(b);
            }
            if (ReferenceEquals(aSuper, bSuper))
            {
                return(aSuper);
            }

            var ancestrorsOfA = a.Ancestrors();

            foreach (var ancestror in b.Ancestrors())
            {
                if (ancestrorsOfA.Contains(ancestror))
                {
                    return(ancestror);
                }
            }

            return(null);
        }