Cadisplaylink and Bezier curves for specific use
Effect:
////displayview.m//customanimation////Created by LV on 16/1/6.//copyright©2016 year Wieye. All rights reserved.//#import "DisplayView.h"@interfaceDisplayview () @property (nonatomic, strong) Cadisplaylink*DisplayLink, @property (nonatomic, assign) cgfloat to; @property (nonatomic, assign) cgfloat from;@end@implementationDisplayview-(Instancetype) initWithFrame: (cgrect) frame{ Self=[Super Initwithframe:frame]; if(self) {NSLog (@"Init"); Self.backgroundcolor=[Uicolor Clearcolor]; } returnSelf ;}- (void) DrawRect: (cgrect) rect{NSLog (@"DrawRect"); [[Uicolor Purplecolor] setfill]; Calayer*layer =Self.layer.presentationLayer; CGFloat Progress=1-(layer.position.y-self.to)/(Self.from-self.to); CGFloat height=cgrectgetheight (rect); CGFloat deltaheight= height/2* (0.5-Fabs (Progress-0.5)); Cgpoint TopLeft= Cgpointmake (0, Deltaheight); Cgpoint TopRight=Cgpointmake (Cgrectgetwidth (rect), deltaheight); Cgpoint Bottomleft= Cgpointmake (0, height); Cgpoint BottomRight=Cgpointmake (Cgrectgetwidth (rect), height); Uibezierpath* Path =[Uibezierpath Bezierpath]; [Path Movetopoint:topleft]; [Path Addquadcurvetopoint:topright Controlpoint:cgpointmake (Cgrectgetmidx (rect),0)]; [Path Addlinetopoint:bottomright]; [Path Addquadcurvetopoint:bottomleft Controlpoint:cgpointmake (Cgrectgetmidx (rect), height-Deltaheight)]; [Path Closepath]; [path fill];}#pragmaMark-public action-(void) Startanimationfrom: (CGFloat) from to: (cgfloat) to{if(Self.displaylink = =Nil) {NSLog (@"startanimation"); Self.from=From ; Self.to=to ; Self.displaylink=[Cadisplaylink displaylinkwithtarget:self selector: @selector (tick:)]; [Self.displaylink Addtorunloop:[nsrunloop Currentrunloop] formode:nsdefaultrunloopmode]; } [UIView animatewithduration:1Delay0Usingspringwithdamping:0.3Initialspringvelocity:0Options0animations:^{Self.center=Cgpointmake (self.center.x, self.to); } Completion:^(BOOL finished) {[Self stopanimation]; }];}- (void) stopanimation{if(Self.displaylink! =Nil) {[Self.displaylink invalidate]; Self.displaylink=Nil; }}#pragmaMark-private action-(void) Tick: (Cadisplaylink *) displaylink{[self setneedsdisplay];}@end
#import <UIKit/UIKit.h>@interface displayview:uiview-(void) Startanimationfrom: (CGFloat) from to: (CGFloat) to; -(void) stopanimation; @end
The jelly Effect of iOS