实现扫描区域红线上下移动的动能
#pragma mark -增加扫描线
-(void)addScanLine
{
UIView *lineView = [[UIView alloc]init];
[lineView setBackgroundColor:[UIColor redColor]];
CGFloat w = self.pageSize.width - 2 * 50 - 2 * 20;
CGFloat h = 1;
CGFloat x = (self.pageSize.width - w) / 2;
CGFloat y = (self.pageSize.height - h) / 2;
[lineView setFrame:CGRectMake(x, y, w, h)];
[self.view addSubview:lineView];
dView = lineView;
}
#pragma mark -设定timer
-(void)addTimer
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.02f target:self selector:@selector(timerControl) userInfo:nil repeats:YES];
self.flag = 1;
}
#pragma mark -对扫描线的控制
-(void)timerControl
{
CGPoint point = dView.frame.origin;
CGSize size = dView.frame.size;
if (self.flag == 1) {
if (point.y >= CGRectGetMaxY(self.rectangleRect) - 16) {
self.flag = 0;
}
else{
point.y += 2;
}
}
if (self.flag == 0) {
if (point.y <= self.rectangleRect.origin.y + 16) {
self.flag = 1;
}
else {
point.y -= 2;
}
}
[dView setFrame:CGRectMake(point.x,point.y,size.width,size.height)];
}