#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