Getting a UIView's visible rectangle

iphone, uiscrollview, uiview

Solution

This should do the trick

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

Use that in the UIView and it should get you the rectangle (if any) that represents the visible section of that view in it's superview (The UIScrollView). I'm assuming here that there is no view between them in the hierarchy, but if there is, fiddling the code should be trivial.

Hope I could help!

Problem

I have a `UIScrollView` that contains a custom `UIView`. Inside the custom `UIView`, I'd like to know the rectangle in which it's visible (i.e. not clipped). The quick-n-dirty solution is to have the custom UIView assume that the parent is a `UIScrollView` and get the content size through it, but I'm looking for a better solution that doesn't involve make such assumptions.

Original source