I've got this animation that I'd like to run but I only want the animation to run when a user has scrolled down and the item that is in the scrollview is now visible on the users screen. Is there a way to check if a view is currently visible on the users screen to then enable this animation to run? Thank you in advance!
user1940321
问问题
1102 次
1 回答
5
One thing you could do is the following:
First, get the currently visible area of your scroll view. That is going to be the scroll view's bound
plus the contentOffset
.
Second, use the CGRectContainsRect()
function to determine if your view's frame is inside the visible area.
Here is some example code:
CGRect visibleRect;
visibleRect.size = myScrollView.bounds.size;
visibleRect.origin = myScrollView.contentOffset;
CGRect containedViewRect = myView.bounds;
if ( CGRectContainsRect( visibleRect, containedViewRect) && !myView.hidden )
{
// The view is visible!
}
Hope this helps!
于 2013-10-14T19:45:00.960 回答