views:

347

answers:

3

Is there a way to get a notification, a callback or some other means to call a method whenever a UIView becomes visible for the user, i.e. when a UIScrollview is the superview of some UIViews, and the ViewController of such a UIView shall get notified when its view is now visible to the user?

I am aware of the possible, but not so elegant solution of checking to which position the ScrollView scrolled (via UIScrollViewDelegate-methods) and compute if either one of the subviews is visible...
But I'm looking for a more universal way of doing this.

+2  A: 

If your view is exhibiting behavior, it should be within a view controller. On a view controller, the viewDidAppear method will be called each time the view appears.

- (void)viewDidAppear:(BOOL)animated
Ty
The problem with viewDidAppear is, that it only get's called when using a Navigation-Controller. In my case, the views get *scrolled* off the screen, then get scrolled back. Scrolling seems not to trigger viewDidAppear....
arne_
A: 

view's layer property should tell us if that view is visible or not

[view.layer visibleRect];

but this isnt working for me.

So work around could be to use UiScrollView contentOffset property to calculate if particular view is visible or not.

Saqib Saud
A: 

I don't think there's a universal way to do this for views. Sounds like you're stuck with scrollViewDidEndScrolling and other ScrollViewDelegate methods. But I'm not sure why you say it's elegant, they're quite straightforward.

Jaanus