0

I wanted to animate set of UIImageViews within UIScrollView(That part is already done). But the animations should start only when the user scrolls the scrollview to its specific position. In other words, animation should start only when that particular UIImageVIew is visible.

smartsanja
  • 4,413
  • 9
  • 58
  • 106
  • no direct way but [this answer](http://stackoverflow.com/a/2950979/2857130) should help. Although it will get heavy because `-scrollViewDidScroll:` will be called too often. Anyways... – staticVoidMan Sep 02 '14 at 05:28

2 Answers2

1
  1. Implement scrollView delegate's scrollViewDidScroll:.

  2. In scrollViewDidScroll: implementation: Get the visible rect of the contentView of the scrollview. Here's how.

  3. Check if the subview you want to animate is within the visible rect using CGRectContainsRect().

This is not tested but hope this help:

- (void) scrollViewDidScroll:(UIScrollView *)scrollView
{   
     // get the scrollView's contentView visible rect
     // from here: https://stackoverflow.com/questions/868288/getting-the-visible-rect-of-an-uiscrollviews-content
     CGRect visibleRect;
     visibleRect.origin = scrollView.contentOffset;
     visibleRect.size = scrollView.contentSize;

     if( CGRectContainsRect(visibleRect, rectOfScrollViewSubviewYouWantToAnimate) )
     {
          // NOTE: This will be called multiple times as the scrollview moves 
          // do your animation here:
     }
     else
     {
          // rectOfScrollViewSubviewYouWantToAnimate is out of scrollView Visible area
     }
}
Community
  • 1
  • 1
Allan Macatingrao
  • 2,071
  • 1
  • 20
  • 28
0

Please go to this page , This might help you . I tried it on one imageview. Similarly you can perform this for all imageview in your code.

[blog] : http ://icodeguru.blogspot.in/2014/09/animated-imageview-stops-animating-when.html