Zigglzworth
Zigglzworth

Reputation: 6813

iOS - When a UIView appears on screen what method does it call?

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 ?

Upvotes: 4

Views: 3791

Answers (3)

Filip Radelic
Filip Radelic

Reputation: 26683

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.

Upvotes: 2

William Falcon
William Falcon

Reputation: 9813

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.

Upvotes: 0

Wain
Wain

Reputation: 119031

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).

Upvotes: 1

Related Questions