知乎日报-DailyNewsContent页—PreView

1、加载动画

- (void)initSubViews {
    ...//加载其他UIView

    //最后增加数据加载进度条,覆盖其他UIView
    _preView = [[PreView alloc] initWithFrame:kScreenBounds];
    [self.view addSubview:_preView];
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        circleLayer = [[CAShapeLayer alloc] init];
        circleLayer.fillColor = [UIColor clearColor].CGColor;
        circleLayer.strokeColor = [UIColor grayColor].CGColor;
        circleLayer.lineWidth = 10.f;
        circleLayer.path = [UIBezierPath bezierPathWithArcCenter:self.center radius:80 startAngle:0 endAngle:M_PI*2 clockwise:YES].CGPath;
        circleLayer.lineCap = kCALineCapRound;
        [self.layer addSublayer:circleLayer];
        [self loadingAnimation];
    }
    return  self;
}

- (void)loadingAnimation {
    CABasicAnimation *strokeStartAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
    strokeStartAnimation.fromValue = @(-1);
    strokeStartAnimation.toValue = @(1);

    CABasicAnimation *strokeEndAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    strokeEndAnimation.fromValue = @(0);
    strokeEndAnimation.toValue = @(1);

    CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
    group.animations = @[strokeStartAnimation,strokeEndAnimation];
    group.repeatCount = 10;
    group.duration = 2.4;
    [circleLayer addAnimation:group forKey:nil];

}

2、数据加载完成以后,移除UIView

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
        //更新其他UIView
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [_preView removeFromSuperview];
        });
    }
}
Copyright © 翻这个墙 2016 all right reserved,powered by Gitbook该文件修订时间: 2016-04-07 00:40:09