// // KWMLoadingView.m // iCemarose // // Created by 陈荣科 on 2016/11/17. // Copyright © 2016年 kollway. All rights reserved. // #import "KWMLoadingView.h" @implementation KWMLoadingView - (instancetype)init{ if (self = [super init]) { [self initContentView]; } return self; } - (instancetype)initWithCoder:(NSCoder *)aDecoder{ if (self = [super initWithCoder:aDecoder]) { [self initContentView]; } return self; } - (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { [self initContentView]; } return self; } - (void)awakeFromNib{ [super awakeFromNib]; [self initContentView]; } - (void)initContentView{ [[NSBundle mainBundle] loadNibNamed:@"KWMLoadingView" owner:self options:nil]; _vContent.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); [self addSubview:_vContent]; } - (void)startAnimation{ CABasicAnimation* rotationAnimation; rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ]; rotationAnimation.duration = 0.75; rotationAnimation.cumulative = YES; rotationAnimation.repeatCount = CGFLOAT_MAX; [self.ivLoading.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; } - (void)stopAnimation{ NSLog(@"停止动画"); //[_customView.layer removeAllAnimations]; [self pauseLayer:_ivLoading.layer]; } //暂停 - (void)pauseLayer:(CALayer*)layer{ CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; layer.speed = 0.0; layer.timeOffset = pausedTime; } //恢复 - (void)resumeLayer:(CALayer*)layer{ CFTimeInterval pausedTime = [layer timeOffset]; layer.speed = 1.0; layer.timeOffset = 0.0; layer.beginTime = 0.0; CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime; layer.beginTime = timeSincePause; } @end