Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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 xcode,UIScrollView保持循环滚动动画_Ios_Objective C_Uiscrollview - Fatal编程技术网

Ios xcode,UIScrollView保持循环滚动动画

Ios xcode,UIScrollView保持循环滚动动画,ios,objective-c,uiscrollview,Ios,Objective C,Uiscrollview,客观的 尝试创建滚动视图时,它可以自动向左滚动。完成后将自动向右滚动。然后重复 即使动画尚未完成,滚动动画也会继续循环并继续使用“AfterDone”方法 - (void) afterAnimationStops{ float newOffSetX = _tableview.bounds.size.width-wContentBgImg; NSLog(@"Inside AutoMove > %d",LzAutoMove); if(leftright==1 && LzAu

客观的

  • 尝试创建滚动视图时,它可以自动向左滚动。完成后将自动向右滚动。然后重复
即使动画尚未完成,滚动动画也会继续循环并继续使用“AfterDone”方法

- (void) afterAnimationStops{
float newOffSetX = _tableview.bounds.size.width-wContentBgImg;
NSLog(@"Inside AutoMove > %d",LzAutoMove);
if(leftright==1 && LzAutoMove==0)
{
    NSLog(@"Come In > 1");
    LzAutoMove = 1;
    leftright = 2;
    [UIScrollView animateWithDuration:3.0f
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         [UIScrollView beginAnimations:@"scrollAnimation" context:nil];
                         [UIScrollView setAnimationDuration:3.0f];
                         LzcurrentLocation = (-newOffSetX);
                         [imgCell.scrollview setContentOffset:CGPointMake((-newOffSetX), 0)];
                         [UIScrollView commitAnimations];
                     }
                     completion:^(BOOL finished){
                         if (finished) {
                             [self afterDone];
                         }
                     }];
}else{
    if(LzAutoMove==0){
    NSLog(@"Come In > 2");
        LzAutoMove = 1;
        leftright = 1;
        [UIScrollView animateWithDuration:3.0f
                                    delay:0.0f
                                  options:UIViewAnimationOptionCurveEaseOut
                               animations:^{
                                   [UIScrollView beginAnimations:@"scrollAnimation" context:nil];
                                   [UIScrollView setAnimationDuration:3.0f];
                                   LzcurrentLocation = 0;
                                   [imgCell.scrollview setContentOffset:CGPointMake(0, 0)];
                                   [UIScrollView commitAnimations];
                                   //[UIScrollView setAnimationDidStopSelector:@selector(afterDone)];
                               }
                               completion:^(BOOL finished){
                                   if (finished) {
                                       [self afterDone];
                                   }
                               }];

    }

}
}

- (void) afterDone{
    NSLog(@"Done");
    LzAutoMove = 0;
    [self afterAnimationStops];
}

我还在学习如何使用“动画完成”的方法,是不是有人能告诉我哪里做错了?谢谢

您可以为动画选项使用
UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
标志,动画将在每次完成后自动重复并反转到原始状态

[UIView animateWithDuration:3.0f
                            delay:0.0f
                          options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
                       animations:^{
                           [imgCell.scrollview setContentOffset:contentOffset];
                       }
                       completion:^(BOOL finished){
                       }];

我不是很确定,但我可以看到一个永无止境的递归,这可能导致出问题memory@bhargavg,用户可以中断它。因此,如果没有用户中断,它将永远不会结束。我的坏,它不会导致任何递归。