Up and down jitter progress bar

Source: Internet
Author: User

#import <UIKit/UIKit.h>@interface  tjshakeprogressview:uiview@property (nonatomic, Assign) cgfloat progress; @end

//

tjshakeprogressview.m

Tjshakeprogressview

//

Created by MJ on 15/7/6.

Copyright (c) years TJ. All rights reserved.

//

#import "TJShakeProgressView.h"

@interface tjshakeprogressview ()

{

UIView *firstview;

UIView *secondview;

UIView *thirldview;

UIView *fourview;

UIView *contentview;

nsmutablearray *viewarray;

Nsinteger count;

cgfloat temp;

}

@end

@implementation Tjshakeprogressview

-(void) awakefromnib

{

[Super awakefromnib];

[self setUp];

}

-(void) setUp

{

Contentview = [[UIView alloc]init];

Contentview. Translatesautoresizingmaskintoconstraints = NO;

Contentview. BackgroundColor = [uicolor clearcolor];

Firstview = [[UIView alloc]init];

Secondview = [[UIView alloc]init];

Thirldview = [[UIView alloc]init];

Fourview = [[UIView alloc]init];

[self addsubview:contentview];

    nsarray *contentview_h = [nslayoutconstraint constraintswithvisualformat:@ "h:|[contentview]|" options:0 metrics:nil views :nsdictionaryofvariablebindings ( Contentview

nsarray *contentview_v = [nslayoutconstraint constraintswithvisualformat:@ "v:|[ Contentview]| " options:0 metrics:nil views : Nsdictionaryofvariablebindings(contentview)];

[self addconstraints: contentview_h];

[self addconstraints: contentview_v];

Viewarray = [nsmutablearray arraywitharray:@[firstview,Secondview ,thirldview,Fourview]];

for (UIView *views in viewarray)

{

        Views. Backgroundcolor  = [uicolor colorwithred :arc4random ()%255/256.f green:arc4random ()%255/256.f blue:arc4random ()%255< Span class= "S5" >/256.f alpha: 1.f]

Views. translatesautoresizingmaskintoconstraints = NO;

[contentview addsubview: views];

nslayoutconstraint *constraint_bottom = [nslayoutconstraint< Span class= "S5" > constraintwithitem:views attribute :nslayoutattributebottom relatedby :nslayoutrelationequal toitem :contentview attribute:< Span class= "S1" >nslayoutattributebottom multiplier: 1.f constant:0.f

[contentview addconstraint: constraint_bottom];

}

    nsarray *allview_h = [ nslayoutconstraint constraintswithvisualformat :@ "H:|-[firstview]-[secondview (Firstview)]-[thirldview (SecondView)]-[ Fourview (Thirldview)]-| " options:0 metrics:nil views :nsdictionaryofvariablebindings (firstView< Span class= "S5" >,secondview,thirldview,< Span class= "S8" >fourview

[contentview addconstraints: allview_h];

}

-(void) setprogress: (cgfloat ) Progress

{

if (progress<0.f) {

_progress = 0.0f;

}

Else if (progress<=1.0f)

{

_progress = progress;

}

Else

{

_progress = 1.f;

}

for (UIView *views in viewarray)

{

count+ +;

Temp = count%2? 0.75:0.45;

[Views needsupdateconstraints];

Nslayoutconstraint *constraint_height = [nslayoutconstraint Constraintwithitem:views attribute: Nslayoutattributeheight relatedby: Nslayoutrelationequal toitem:contentview< Span class= "S5" > attribute:nslayoutattributeheight multiplier:(_progress*< Span class= "S8" >temp) constant:0.f

[contentview addconstraint: constraint_height];

[Views layoutifneeded];

cabasicanimation *basic = [cabasicanimation animationwithkeypath:@ "POSITION.Y" ];

Basic. Tovalue = @ (_progress*contentview. Bounds. Size. Height);

Basic. repeatduration = maxfloat;

Basic. Duration = 0.60f;

Basic. autoreverses= YES;

[Views. layer addanimation: Basic forkey:@ "Test"];

}

}

@end

#import " ViewController.h " #import " TJShakeProgressView.h " @interface  *Progressview; @end @implementation Viewcontroller-(void) viewdidload {    [super Viewdidload];            0.81 ;}

Progress bar up and down jitter

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.