不好意思,刚才测试了一下,原来以前的动画停止方法没有效果,不应该用 [self.view.layer removeAllAnimations]; 应该用 [_line.layer removeAllAnimations];
这个是二维码扫描时的扫描线的动画效果:
-(void)scanAnimation
{
[UIViewbeginAnimations:@"animationID"context:NULL];
[UIViewsetAnimationDuration:4];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];
//[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:_line cache:YES]; (这一句不要写,不然会出问题,亲身体会)
[UIViewsetAnimationRepeatCount:100000];
[_line setFrame:CGRectMake(50,270+44-11+5,220,11)];
[UIViewcommitAnimations];
}
那么commit后如何停止呢(一句话即可,记得加上头文件 #import <QuartzCore/QuartzCore.h>):
[_line.layer removeAllAnimations]; (如果是直接改变self.view的属性,例如alpha值,则用 [self.view removeAllAnimations];)
下面将我的二维码扫描的扫描线方法记下吧:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationControllersetNavigationBarHidden:YESanimated:NO];
[_readerView start];
_line.hidden =NO;
_line.frame = CGRectMake(50, 50+44-4,220,11); //这个地方貌似得复原下
[self scanAnimation];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.view.layer removeAllAnimations];
[_readerView stop];
}