簡單的圓圈動畫,自己看的

圓圈動畫

-(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));

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • (一)Masonry介紹 Masonry是一個輕量級的布局框架 擁有自己的描述語法 采用更優雅的鏈式語法封裝自動布...
    木易林1閱讀 2,385評論 0 3
  • Masonry是一個輕量級的布局框架,擁有自己的描述語法,采用更優雅的鏈式語法封裝自動布局,簡潔明了并具有高可讀性...
    3dcc6cf93bb5閱讀 1,826評論 0 1
  • Masonry手寫Autolayout專題 Masonry介紹與使用實踐:快速上手Autolayout http:...
    Kevin_Junbaozi閱讀 1,177評論 0 2
  • iOS_autoLayout_Masonry 概述 Masonry是一個輕量級的布局框架與更好的包裝AutoLay...
    指尖的跳動閱讀 1,195評論 1 4
  • 深夜無眠。 悶熱的夏夜,蚊蟲在耳邊嗡鳴,電腦微弱的燈光打在手上,照亮了根根毛發。 頭頂的風扇一圈又一圈無休止地轉動...
    戴夜白閱讀 234評論 0 2