ios - CAShapeLayer设计了一个倒计时动画 在不断开始和结束过程中越走越快
怪我咯
怪我咯 2017-04-18 09:52:33
0
1
537
@property(nonatomic,strong)CADisplayLink *timer;//定时器

#pragma mark - lazyInstall
-(CAShapeLayer*)shapeLayer {
    if (!_shapeLayer) {
        //创建出CAShapeLayer
        self.shapeLayer = [CAShapeLayer layer];
        self.shapeLayer.frame = CGRectMake(0, 0, 57, 80);
        self.shapeLayer.position = self.potrait.center;
        self.shapeLayer.fillColor = [UIColor clearColor].CGColor;
        
        //设置线条的宽度和颜色
        self.shapeLayer.lineWidth = 2.0f;
        self.shapeLayer.strokeColor = [UIColor greenColor].CGColor;
       
        //创建出圆形贝塞尔曲线
        UIBezierPath *circlePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 57, 80) cornerRadius:3];
        //让贝塞尔曲线与CAShapeLayer产生联系
        self.shapeLayer.path = circlePath.CGPath;
    }
    return _shapeLayer;
}

#pragma mark - Timer
-(void)startCycle {//用定时器模拟数值输入的情况
    [self.layer addSublayer:self.shapeLayer];
    
    _shapeLayer.strokeStart = 0;
    _shapeLayer.strokeEnd = 1;

    _timer = [CADisplayLink displayLinkWithTarget:self selector:@selector(circleAnimationType)];
    _timer.frameInterval = 1; //设置刷新60次响应一次
    [_timer addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}

- (void)circleAnimationType {//用定时器调用的方法
    if (_shapeLayer.strokeStart != 1) {
        _shapeLayer.strokeStart += 倒计时时间;
    }
}

-(void)endCycle {
    [_timer invalidate];
    _timer = nil;
    
    _shapeLayer.strokeStart = 1;
    _shapeLayer.strokeEnd = 0;
//    [_timer setFireDate:[NSDate distantFuture]];
}

其中-(void)startCycle是开始倒计时方法,-(void)endCycle是结束倒计时方法。经过不断的开始和结束,动画的倒计时时长越来越短,是为什么??求大神解惑

怪我咯
怪我咯

走同样的路,发现不同的人生

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!