Use CADisplayLink to implement jelly effect animation (learned from Glow Technical Team) and cadisplaylinkglow
Use CADisplayLink for jelly effect Animation
CADisplayLink object is a timer object that allows your application to synchronize its drawing to the refresh rate of the display.
Github
1. Define a View@ InterfaceJellyView ()
@ Property (strong, nonatomic) CADisplayLink * displayLink;
@ Property (nonatomic) CGFloat from;
@ Property (nonatomic) CGFloat;
@ Property (nonatomic) BOOL animating;@ End
2. Draw View and move path-(Void) drawRect :( CGRect) rect {
CALayer * layer = self. layer. presentationLayer;
CGFloat progress = 1;
If (! Self. animating ){
SS = 1;
} Else {
Progress = 1-(layer. position. y-self. to)/(self. from-self. );
}
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 = [UIBezierPathbezierPath];
[[UIColorblueColor] setFill];
[Path moveToPoint: topLeft];
[Path addQuadCurveToPoint: topRightcontrolPoint: CGPointMake (CGRectGetMidX (rect), 0)];
[Path addLineToPoint: bottomRight];
[Path addQuadCurveToPoint: bottomLeftcontrolPoint: CGPointMake (CGRectGetMidX (rect), height-deltaHeight)];
[Path closePath];
[Path fill];}
3. Add CADisplayLink-(Void) startAnimationFrom :( CGFloat) from to :( CGFloat) {
Self. from = from;
Self. to =;
Self. animating = YES;
If (self. displayLink = nil ){
Self. displayLink = [CADisplayLinkdisplayLinkWithTarget: selfselector: @ selector (tick :)];
[Self. displayLinkaddToRunLoop: [nsunloopcurrentrunloop]
ForMode: NSDefaultRunLoopMode];
}
}
-(Void) completeAnimation {
Self. animating = NO;
[Self. displayLinkinvalidate];
Self. displayLink = nil;
}
-(Void) tick :( CADisplayLink *) displayLink {
[SelfsetNeedsDisplay];}
4. CallCGFloat from = CGRectGetHeight (self. view. bounds)-CGRectGetHeight (self. blockView. bounds)/2; CGFloat to = 100; self. blockView. center = CGPointMake (self. blockView. center. x, from); [self. blockViewstartAnimationFrom: fromto: to];
[UIViewanimateWithDuration: 1 delay: 0 usingSpringWithDamping: 0.85 initialSpringVelocity: 0 options: 0 animations: ^ {
Self. blockView. center = CGPointMake (self. blockView. center. x, );
} Completion: ^ (BOOL finished) {[self. blockViewcompleteAnimation];}];