2011-12-05 47 views
1

我目前有一个默认的循环动画,当视图出现时淡入淡出,当数据的背景处理完成时,它将停止当前动画加载新的动画,根据新的图片。如何停止循环动画并用新值再次调用

我不能看到停止使用[self.view.layer removeAllAnimations];[self.imageViewBottom.layer removeAllAnimations];[self.imageViewTop.layer removeAllAnimations];

-(void)nextAnimation:(float)previousWidth { 

//picture loop 
imageViewTop.image = imageViewBottom.image; 
imageViewBottom.image = [imageArray objectAtIndex:[imageArray count] - 1]; 

[imageArray insertObject:imageViewBottom.image atIndex:0]; 
[imageArray removeLastObject]; 
imageViewTop.alpha = 1.0; 
imageViewBottom.alpha = 0.0; 

[UIView animateWithDuration:4.0 
       animations:^{ 
        imageViewTop.alpha = 0.0; 
        imageViewBottom.alpha = 1.0; 
        } 
       completion:^(BOOL completed){ 
        [self nextAnimation:stringsize.width]; 
       } 
]; 



-(void)foundSetup 
{ 
    //[imageViewTop removeFromSuperview]; 
    //[imageViewBottom removeFromSuperview]; 
    //[buttonCaption removeFromSuperview]; 
    [self.view.layer removeAllAnimations]; 
    [self.imageViewBottom.layer removeAllAnimations]; 
    [self.imageViewTop.layer removeAllAnimations]; 


    //[self.imageArray removeAllObjects]; 
    //self.imageArray = foundImageArray; 
} 
+3

'[imageViewTop.layer removeAllAnimations];'和'[imageViewBottom.layer removeAllAnimations];'? – Till

+1

@Till,你应该将其作为答案发布。 self.view没有动画,因此删除它们毫无意义。 – jrturton

+0

感谢直到,还没有动画 – Desmond

回答

3
[UIView animateWithDuration:4.0     
    animations:^{      
    imageViewTop.alpha = 0.0;      
    imageViewBottom.alpha = 1.0;      
    }     
    completion:^(BOOL completed){      
    [self nextAnimation:stringsize.width];     
    } 

这里,在完成块中,无论动画是否被取消,您都将再次调用下一个动画方法。

里面你完成块,只能打电话nextAnimation如果完成== YES:

completion:^(BOOL completed){      
if (completed)   
    [self nextAnimation:stringsize.width];     
    } 

这一点,再加去除实际被动画的意见动画由截止建议,应该为你做。

+0

真棒.....我错过了这....感谢Jrturton。 – Desmond

1

动画您可以用计时器去,以及创建一个定时器对象,并调用通过对象这个功能一旦乌尔后台处理得到了无效对象[boothTimer1无效]并再次调用。在我的一个应用程序中,我已经完成了类似的场景。在.h中声明boothTimer1

NSTimer * boothTimer1; self.boothTimer1 = [NSTimer scheduledTimerWithTimeInterval:duration target:self selector:@selector(ur function)userInfo:nil repeatats:NO];

现在你可以在你的后台处理完成时使计时器无效。

+0

你将如何做到这一点,你介意分享一些示例代码?因为我使用的是位置,所以时间可能每次都不一样。 – Desmond

+0

如果iOS是20年前建立的系统,则可以使用此类解决方案。幸运的是,它不是为穴居人而建的,因此使用计时器对象与强制重绘是不合适的。 – Till

+0

@Till:如果是这种情况,那么它应该已被苹果弃用。 – iamsult