Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a UIView's visible rectangle

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.

like image 212
Dia Kharrat Avatar asked Dec 07 '10 03:12

Dia Kharrat


2 Answers

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!

like image 84
foslock Avatar answered Nov 15 '22 08:11

foslock


It would help if you would give more info on what is that you are trying to accomplish.

If you want to know the size of the super view you can do this:

CGRect superFrame = [self superview].frame;
like image 35
Cyprian Avatar answered Nov 15 '22 09:11

Cyprian