二维码扫描动画


#import “ViewController.h”

@interface ViewController ()

@property (nonatomicstrongNSTimer *timer;

@property (nonatomicstrongUIView *line;

@property (nonatomicassignint num;

@property (nonatomicassignBOOL goUp;//从下往上

@end

@implementation ViewController

– (void)viewDidLoad {

    [super viewDidLoad];

    UIView *boxView = [[UIView alloc]initWithFrame:CGRectMake((self.view.bounds.size.width200)/2100200200)];

    boxView.layer.borderColor = [UIColor redColor].CGColor;

    boxView.layer.borderWidth = 0.5;

    [self.view addSubview:boxView];

    

    self.line = [[UIView alloc]initWithFrame:CGRectMake(002001)];

    self.line.backgroundColor = [UIColor redColor];

    [boxView addSubview:self.line];

    

    self.timer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(scanAnimation) userInfo:nil repeats:YES];

}

– (void)scanAnimation {

    if (self.goUp == NO) {

        self.num ++;

        self.line.frame = CGRectMake(0_num2001);

        if ((2*_num == 200 )) {

            self.goUp = YES;

        }

    else {

        self.num –;

        self.line.frame = CGRectMake(0200_num2001);

        if (self.num == 0) {

            self.goUp = NO;

        }

    }

}

发表评论