简单的圆圈动画,自己看的

圆圈动画

-(UIView*)circleViewWithColor:(UIColor*)color Title:(NSString*)title titleValue:(NSString*)titleValue{

UIView*circleView = [[UIViewalloc]init];

circleView.layer.cornerRadius=30;

circleView.layer.masksToBounds=YES;

//底部的灰色圆圈

CAShapeLayer*bottomShapeLayer = [CAShapeLayerlayer];

bottomShapeLayer.strokeColor=XKColor(229,229,229).CGColor;

bottomShapeLayer.fillColor= [UIColorclearColor].CGColor;

bottomShapeLayer.lineWidth=3;

bottomShapeLayer.path= [UIBezierPathbezierPathWithRoundedRect:CGRectMake(0,0,60,60)cornerRadius:30].CGPath;

[circleView.layeraddSublayer:bottomShapeLayer];

///橘黄色的layer

CAShapeLayer*ovalShapeLayer = [CAShapeLayerlayer];

ovalShapeLayer.strokeColor= color.CGColor;

ovalShapeLayer.fillColor= [UIColorclearColor].CGColor;

ovalShapeLayer.lineWidth=3;

ovalShapeLayer.path= [UIBezierPathbezierPathWithRoundedRect:CGRectMake(0,0,60,60)cornerRadius:30].CGPath;

[circleView.layerinsertSublayer:ovalShapeLayerabove:bottomShapeLayer];

///起点动画

//CABasicAnimation * strokeStartAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];

//strokeStartAnimation.fromValue = @(1.0);

//strokeStartAnimation.toValue = @(0.2);

///终点动画

CABasicAnimation* strokeEndAnimation = [CABasicAnimationanimationWithKeyPath:@"strokeEnd"];

strokeEndAnimation.fromValue=@(0.0);

NSString*tempStr;

if([titleValuerangeOfString:@"%"].length) {

tempStr = [titleValuesubstringToIndex:titleValue.length-1];

}else{

tempStr = titleValue;

}

CGFloatscale = [tempStrfloatValue] /100.0;

strokeEndAnimation.toValue=@(scale >1?1:scale);

///组合动画

CAAnimationGroup*animationGroup = [CAAnimationGroupanimation];

animationGroup.animations=@[strokeEndAnimation];

animationGroup.duration=1.0;

animationGroup.timingFunction= [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseOut];

animationGroup.repeatCount=1;

animationGroup.fillMode=kCAFillModeForwards;

animationGroup.removedOnCompletion=NO;

[ovalShapeLayeraddAnimation:animationGroupforKey:nil];

UILabel*circleTitle = [[UILabelalloc]init];

circleTitle.text= title;

circleTitle.textColor=XKSubTitleOrContentColor;

circleTitle.font= [UIFontsystemFontOfSize:10];

[circleViewaddSubview:circleTitle];

UILabel*circleValue = [[UILabelalloc]init];

circleValue.text= titleValue;

circleValue.textColor= color;

circleValue.font= [UIFontsystemFontOfSize:16];

[circleViewaddSubview:circleValue];

//[_circleView mas_makeConstraints:^(MASConstraintMaker *make) {

//make.top.equalTo(_workPosition.mas_bottom).offset(10);

//make.centerX.equalTo(weakself.mas_centerX);

//make.size.mas_equalTo(CGSizeMake(60, 60));

//}];

[circleTitlemas_makeConstraints:^(MASConstraintMaker*make) {

make.centerY.equalTo(circleView.mas_centerY).offset(-10);

make.centerX.equalTo(circleView.mas_centerX);

}];

[circleValuemas_makeConstraints:^(MASConstraintMaker*make) {

make.centerY.equalTo(circleView.mas_centerY).offset(10);

make.centerX.equalTo(circleTitle.mas_centerX);

}];

returncircleView;

}


宽度限制伸缩

NSLog(@"%f----%f",CGRectGetMinX(_DistanceLabel.frame),CGRectGetMaxX(_userHeadImageView.frame));

CGFloatwidth = (CGRectGetMinX(_DistanceLabel.frame) -20) - (CGRectGetMaxX(_userHeadImageView.frame) +8);

[_userNamemas_makeConstraints:^(MASConstraintMaker*make) {

make.left.equalTo(_userHeadImageView.mas_right).offset(8);

make.width.mas_equalTo(width);

}];

NSLog(@"----%@",NSStringFromCGRect(_userName.frame));

你可能感兴趣的:(简单的圆圈动画,自己看的)