參考http://blog.csdn.net/smking/article/details/8424245
一個掃描動畫,示例代碼
// 上下掃動條
UIImageView *sweepLineView = [[UIImageView alloc] initWithFrame:CGRectMake(1, 20, 198, 2)];
sweepLineView.image = [UIImage imageNamed:@"line"];
[self.scanFrameImageView.layer addSublayer:sweepLineView.layer];
// 創(chuàng)建動畫
CABasicAnimation *anim = [CABasicAnimation animation];
// 描述下修改哪個屬性產生動畫
// 只能是layer屬性
anim.keyPath = @"transform.translation.y";
// 設置值
anim.toValue = [NSNumber numberWithDouble:160];
anim.duration = 2.0;
// 設置動畫執(zhí)行次數(shù)
anim.repeatCount = MAXFLOAT;
// 取消動畫反彈
// 設置動畫完成的時候不要移除動畫
anim.removedOnCompletion = NO;
// 設置動畫執(zhí)行完成要保持最新的效果
anim.fillMode = kCAFillModeForwards;
[sweepLineView.layer addAnimation:anim forKey:nil];