Getting Visible Rect of UIView

2019-07-21 04:06发布

问题:

What's the simplest method to get the visible rect of any arbitrary UIView as a CGRect, assuming that the UIView is only clipped along the edges (no other views breaking it up somewhere in the middle)?

For clarity, this method should not only retrieve the visible rect relative to the view's superview. But relative to all it's ancestors at a minimum and ideally relative to all siblings as well.

回答1:

Try this!

CGRect visibleRect = CGRectIntersection(self.frame, superview.bounds);