Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the visible rect of an UIScrollView's content

How can I go about finding out the rect (CGRect) of the content of a displayed view that is actually visible on screen.

myScrollView.bounds 

The code above works when there's no zooming, but as soon as you allow zooming, it breaks at zoom scales other than 1.

To clarify, I want a CGRect that contains the visible area of the scroll view's content, relative to the content. (ie. if it's a zoom scale 2, the rect's size will be half of the scroll view's size, if it's at zoom scale 0.5, it'll be double.)

like image 960
Kenneth Ballenegger Avatar asked May 15 '09 12:05

Kenneth Ballenegger


1 Answers

Or you could simply do

CGRect visibleRect = [scrollView convertRect:scrollView.bounds toView:zoomedSubview]; 

Swift

let visibleRect = scrollView.convert(scrollView.bounds, to: zoomedSubview) 
like image 96
Trenskow Avatar answered Sep 20 '22 11:09

Trenskow