views:

249

answers:

2

I have a have a strip of UIViews that slides horizontally behind a UIView "window". Only the UIViews within the bounds of the "window" are seen. As a view becomes hidden I would like to be notified so that I can perform some task with the just hidden view. What is the best way to do this?

+1  A: 

Add a callback selector to your animation:

 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:0.5];
 [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:theView cache:NO];
 [UIView setAnimationDidStopSelector:@selector(animationDone)];
 theView.frame = newFrame;
 [UIView commitAnimations];
coneybeare
Whoops, I now realize I gave the misleading impression that this is an animation in which case your answer would be dead on. My bad. Actually the "window" is our friend the UIScrollView. I've looked at the UIScrollView and UIScrollViewDelegate methods and nothing seems to fit the bill.
dugla
A: 

In your UIScrollViewDelegate:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // left and right bounds of the subview in relation to the scrollview
    CGFloat left = mySubview.frame.origin.x - myScrollView.contentOffset.x;
    CGFloat right = left+mySubview.frame.size.width - myScrollView.contentOffset.x;
    if(right<=0 || left>=myScrollView.frame.size.width){
        // The view is not visible
    }
}

this checks if either the left or right side of the subview is visible.

Kelso.b