如何停止循环动画并使用新值再次调用它
我目前有一个默认的循环动画,一旦视图出现就会淡入和淡出,当数据的后台处理完成时,它将停止当前动画并加载新的动画(就新图片而言)。
我看不到使用 [self.view.layer removeAllAnimations];
[self.imageViewBottom.layer removeAllAnimations];
[self.imageViewTop.层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;
}
i currently have a default looping animation which fade in and out once the view appear, when background processing of data are completed it will stop the current animation an load new animation, in terms of new picture.
i can't seen to stop the animation using [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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这里,在完成块中,无论动画是否被取消,您都将再次调用下一个动画方法。
在完成块中,仅在完成== YES时才调用nextAnimation:
这,再加上从Till建议的实际正在动画化的视图中删除动画,应该可以为您完成。
Here, in your completion block, you will call the next animation method again regardless of the animation being cancelled or not.
Inside your completion block, only call nextAnimation if completed == YES:
This, coupled with removing animations from the views that are actually being animated as suggested by Till, should do it for you.
您也可以使用计时器创建一个计时器对象,并在后台处理结束后通过该对象调用此函数,使对象无效 [boothTimer1 invalidate] 并再次调用。在我的一个应用程序中,我已经针对您提到的类似场景进行了操作。在.h
NSTimer*中声明boothTimer1; self.boothTimer1 = [NSTimer ScheduledTimerWithTimeInterval:持续时间目标:self 选择器:@selector(ur 函数) userInfo:nil 重复:NO];
现在,当后台处理完成时,您可以使计时器无效。
You can go with timer as well create a timer object and call this function through that object once ur background processing gets over invalidate the object [boothTimer1 invalidate] and call again. In one of my application i have done for similar scenario u mentioned. Declare boothTimer1 in .h
NSTimer* boothTimer1; self.boothTimer1 = [NSTimer scheduledTimerWithTimeInterval:duration target:self selector:@selector(ur function) userInfo:nil repeats:NO];
Now u can invalidate the timer when ur background processing is completed.