123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- //
- // LBXScanLineAnimation.m
- //
- //
- // Created by lbxia on 15/11/3.
- // Copyright © 2015年 lbxia. All rights reserved.
- //
- #import "LBXScanLineAnimation.h"
- @interface LBXScanLineAnimation()
- {
- int num;
- BOOL down;
- NSTimer * timer;
-
- BOOL isAnimationing;
- }
- @property (nonatomic,assign) CGRect animationRect;
- @end
- @implementation LBXScanLineAnimation
- - (void)stepAnimation
- {
- if (!isAnimationing) {
- return;
- }
-
-
- CGFloat leftx = _animationRect.origin.x + 5;
- CGFloat width = _animationRect.size.width - 10;
-
- self.frame = CGRectMake(leftx, _animationRect.origin.y + 8, width, 8);
-
- self.alpha = 0.0;
-
- self.hidden = NO;
-
- __weak __typeof(self) weakSelf = self;
-
- [UIView animateWithDuration:0.5 animations:^{
- weakSelf.alpha = 1.0;
-
-
-
- } completion:^(BOOL finished)
- {
-
- }];
-
- [UIView animateWithDuration:3 animations:^{
- CGFloat leftx = _animationRect.origin.x + 5;
- CGFloat width = _animationRect.size.width - 10;
-
-
-
- weakSelf.frame = CGRectMake(leftx, _animationRect.origin.y + _animationRect.size.height - 8, width, 4);
-
- } completion:^(BOOL finished)
- {
- self.hidden = YES;
- [weakSelf performSelector:@selector(stepAnimation) withObject:nil afterDelay:0.3];
- }];
- }
- - (void)startAnimatingWithRect:(CGRect)animationRect InView:(UIView *)parentView Image:(UIImage*)image
- {
- if (isAnimationing) {
- return;
- }
-
- isAnimationing = YES;
-
- self.animationRect = animationRect;
- down = YES;
- num =0;
-
- CGFloat centery = CGRectGetMinY(animationRect) + CGRectGetHeight(animationRect)/2;
- CGFloat leftx = animationRect.origin.x + 5;
- CGFloat width = animationRect.size.width - 10;
-
- self.frame = CGRectMake(leftx, centery+2*num, width, 2);
- self.image = image;
-
- [parentView addSubview:self];
-
- [self startAnimating_UIViewAnimation];
-
- // [self startAnimating_NSTimer];
-
-
- }
- - (void)startAnimating_UIViewAnimation
- {
- [self stepAnimation];
- }
- - (void)startAnimating_NSTimer
- {
- timer = [NSTimer scheduledTimerWithTimeInterval:.02 target:self selector:@selector(scanLineAnimation) userInfo:nil repeats:YES];
- }
- -(void)scanLineAnimation
- {
- CGFloat centery = CGRectGetMinY(_animationRect) + CGRectGetHeight(_animationRect)/2;
- CGFloat leftx = _animationRect.origin.x + 5;
- CGFloat width = _animationRect.size.width - 10;
-
- if (down)
- {
- num++;
-
- self.frame = CGRectMake(leftx, centery+2*num, width, 2);
-
- if (centery+2*num > (CGRectGetMinY(_animationRect) + CGRectGetHeight(_animationRect) - 5 ) )
- {
- down = NO;
- }
- }
- else {
- num --;
- self.frame = CGRectMake(leftx, centery+2*num, width, 2);
- if (centery+2*num < (CGRectGetMinY(_animationRect) + 5 ) )
- {
- down = YES;
- }
- }
- }
- - (void)dealloc
- {
- [self stopAnimating];
- }
- - (void)stopAnimating
- {
- if (isAnimationing) {
-
- isAnimationing = NO;
-
- if (timer) {
- [timer invalidate];
- timer = nil;
- }
-
- [self removeFromSuperview];
- }
- [NSObject cancelPreviousPerformRequestsWithTarget:self];
- }
- @end
|