CALayer - , , CAShapeLayer.
CAShapeLayer .
CAAnimation, , layerStart / strokeEnd .
, , , - , . "undefined", .
, , :
http://wareto.com/using-core-animation-groups-to-create-animation-sequences-2
CAAnimationGroups, CAShapeLayer, .
GIF , , - " ", :
, Objective-C, Core Animation Swift. , , .
:
- (IBAction)doMaskAnimation:(id)sender;
{
waretoLogoLarge.hidden = FALSE;
CAShapeLayer *maskLayer = [CAShapeLayer layer];
CGFloat maskHeight = waretoLogoLarge.layer.bounds.size.height;
CGFloat maskWidth = waretoLogoLarge.layer.bounds.size.width;
CGPoint centerPoint;
centerPoint = CGPointMake( maskWidth/2, maskHeight/2);
CGFloat radius = sqrtf(maskWidth * maskWidth + maskHeight * maskHeight)/2;
maskLayer.fillColor = [[UIColor clearColor] CGColor];
maskLayer.strokeColor = [[UIColor blackColor] CGColor];
maskLayer.lineWidth = radius;
CGMutablePathRef arcPath = CGPathCreateMutable();
CGPathMoveToPoint(arcPath, nil, centerPoint.x, centerPoint.y-radius/2);
CGPathAddArc(arcPath,
nil,
centerPoint.x,
centerPoint.y,
radius/2,
3*M_PI/2,
-M_PI/2,
YES);
maskLayer.path = arcPath;
maskLayer.strokeEnd = 0.0;
CFRelease(arcPath);
waretoLogoLarge.layer.mask = maskLayer;
waretoLogoLarge.layer.mask.frame = waretoLogoLarge.layer.bounds;
CABasicAnimation *swipe = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
swipe.duration = 2;
swipe.delegate = self;
[swipe setValue: theBlock forKey: kAnimationCompletionBlock];
swipe.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionLinear];
swipe.fillMode = kCAFillModeForwards;
swipe.removedOnCompletion = NO;
swipe.autoreverses = YES;
swipe.toValue = [NSNumber numberWithFloat: 1.0];
[maskLayer addAnimation: swipe forKey: @"strokeEnd"];
}
, IS Swift , CAShapeLayer
. , , , , .
:
http://wareto.com/swift-piecharts