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?
views:
249answers:
2
+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
2009-09-19 22:30:59
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
2009-09-20 00:07:26
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
2010-01-29 03:05:22