The jelly Effect of iOS

Source: Internet
Author: User

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

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.