分享我碰到的一个bug及解决办法:
背景:我做一个二维码扫描的动画,就是一根“线”,不断上下移动
上代码:
//扫描动画
- (void)scanAnimation
{
_sliceView.frame = CGRectMake((SCREEN_WIDTH-kOverFrameWidth)/2, kSliceViewY_top, kOverFrameWidth-3, kSliceHeight);
[UIView animateWithDuration:1.5f delay:0 options:UIViewAnimationOptionRepeat|UIViewAnimationOptionCurveLinear|UIViewAnimationOptionAllowUserInteraction animations:^{
_sliceView.frame = CGRectMake(_sliceView.frame.origin.x,kSliceViewY_bottom,_sliceView.frame.size.width,_sliceView.frame.size.height);
} completion:^(BOOL finished) {
}];
}
bug:
1.进入后台回来,“线”不动了。
解决:
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scanAnimation) name:UIApplicationDidBecomeActiveNotification object:nil];
}
- (void)viewDidAppe