Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 仅当对象在UIScrollView上可见时才设置对象动画_Ios_Objective C_Animation_Uiscrollview_Uiimageview - Fatal编程技术网

Ios 仅当对象在UIScrollView上可见时才设置对象动画

Ios 仅当对象在UIScrollView上可见时才设置对象动画,ios,objective-c,animation,uiscrollview,uiimageview,Ios,Objective C,Animation,Uiscrollview,Uiimageview,我想在UIScrollView中设置一组UIImageView的动画(该部分已经完成)。但是,只有当用户将scrollview滚动到其特定位置时,动画才会启动。换句话说,动画应该只在特定UIImageVIew可见时启动。请转到此页面,这可能会对您有所帮助。我在一张图片上试过。同样,您可以对代码中的所有imageview执行此操作 [博客]:http://icodeguru.blogspot.in/2014/09/animated-imageview-stops-animating-when.ht

我想在UIScrollView中设置一组UIImageView的动画(该部分已经完成)。但是,只有当用户将scrollview滚动到其特定位置时,动画才会启动。换句话说,动画应该只在特定UIImageVIew可见时启动。

请转到此页面,这可能会对您有所帮助。我在一张图片上试过。同样,您可以对代码中的所有imageview执行此操作

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

  • 实现scrollView代理的
    scrollViewDidScroll:

  • scrollViewDidScroll:
    实现中:获取scrollview的contentView的可见矩形

  • 使用
    CGRectContainsRect()
    检查要设置动画的子视图是否在可见矩形内

  • 这没有经过测试,但希望这有助于:

    - (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
         }
    }
    
    没有直接的方法,但应该有帮助。尽管它会变得很重,因为调用
    -scrollViewDidScroll:
    太频繁了。无论如何。。。