Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get scroll views visible rectangle frame after it scrolls in IOS?

I cannot get the coordinates of visible rectangle in scroll view after şt scrolls. So when I want to add a subview in a visible rect, I cannot. How can I do that?

like image 302
Burak Avatar asked Dec 26 '22 20:12

Burak


1 Answers

CGRect visibleRect = CGRectMake(myScrollView.contentOffset.x, myScrollView.contentOffset.y, myScrollView.contentOffset.x + myScrollView.bounds.size.width, myScrollView.contentOffset.y + myScrollView.bounds.size.height)

This should get you the rect that is currently visible, after scrolling. Not what you must decide is, when you want to calculate the rect. If you want to get this on the fly, then do it in thescrollViewDidScroll method. If you want to get it when user begins scrolling, then do it in scrollViewWillBeginDragging. If you want it after the user is done scrolling and the scrollView comes to rest, do it in scrollViewDidEndDragging and scrollViewDidEndDecelerating.

like image 155
n00bProgrammer Avatar answered Apr 23 '23 03:04

n00bProgrammer