Getting the visible rect of an UIScrollView's content

前端 未结 8 520
故里飘歌
故里飘歌 2020-11-30 19:17

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

8条回答
  •  孤街浪徒
    2020-11-30 19:32

    Shorter version:

    CGRect visibleRect = CGRectApplyAffineTransform(scrollView.bounds, CGAffineTransformMakeScale(1.0 / scrollView.zoomScale, 1.0 / scrollView.zoomScale));
    

    I'm not sure if this is defined behavior, but almost all UIView subclasses have the origin of their bounds set to (0,0). UIScrollViews, however, have the origin set to contentOffset.

提交回复
热议问题