Unfortunately, Philipβs answer to partial border checking is not entirely correct on this line: v1.bounds.intersection(v2.frame).width > 0) && (v1.bounds.intersection(v2.frame).height > 0
The intersection size can be greater than zero, and yet the view will be inside the boundaries of the supervisor.
It also turned out that I cannot safely use equal(to: CGRect) due to the accuracy of CGFloat.
Here is the corrected version:
func outOfSuperviewBounds() -> Bool { guard let superview = self.superview else { return true } let intersectedFrame = superview.bounds.intersection(self.frame) let isInBounds = fabs(intersectedFrame.origin.x - self.frame.origin.x) < 1 && fabs(intersectedFrame.origin.y - self.frame.origin.y) < 1 && fabs(intersectedFrame.size.width - self.frame.size.width) < 1 && fabs(intersectedFrame.size.height - self.frame.size.height) < 1 return !isInBounds }
filletofish
source share