Question

When a UIView appears on screen what method does it call? For example if a have a UIScrollView and I populate it with a hundred views, one under the other, what method is called by the UIViews when they are scrolled such that they appear on screen?

is it -(void)didMoveToWindow ? something else ?

Was it helpful?

Solution

If you are trying to find out when a view gets scrolled into scrollView bounds, it might be easier and probably more performant to use a table view... Table view has methods that let you know when a cell will appear and you can query visible cells at any time.

OTHER TIPS

Specifically for a scroll view, the delegate (usually the controller) can get notified that the scroll view has scrolled. When you get this callback you can write a bit of code that iterates through the subviews and checks which are in the visible frame of the scroll view (using CGRectIntersectsRect, contentOffset and bounds).

None, BUT if you implement the UIScrollView delegate the UIScrollView does call a method that gives you the scroll position and more (many methods, most likely scrollViewDidScroll).

https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollviewdelegate_protocol/Reference/UIScrollViewDelegate.html

To see which view, you have to calculate which view is visible by seeing if CGRectIntersectsRect(scrollView.bounds, subview.frame) returns true.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top