github:https://github.com/potato512/SYAnimation
使用貝賽爾曲線UIBezierPath、陰影對(duì)象CAShapeLayer、基礎(chǔ)類動(dòng)畫(huà)CABasicAnimation實(shí)現(xiàn)。
效果圖如下:

示例代碼:
- (void)lineAnimation{ UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10.0, 340.0, (self.view.frame.size.width - 10.0 * 2), 100.0)]; [self.view addSubview:view]; view.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.2]; UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:view.bounds]; CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init]; shapeLayer.strokeColor = [UIColor purpleColor].CGColor; shapeLayer.fillColor = [UIColor clearColor].CGColor; shapeLayer.lineWidth = 2; shapeLayer.lineJoin = kCALineJoinRound; shapeLayer.lineCap = kCALineCaPRound; shapeLayer.path = bezierPath.CGPath; [view.layer addSublayer:shapeLayer]; CABasicAnimation *pathAnim = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; pathAnim.duration = 5.0; pathAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaSEOut]; pathAnim.fromValue = @(0); pathAnim.toValue = @(1); pathAnim.autoreverses = true; pathAnim.fillMode = kCAFillModeForwards; pathAnim.removedOnCompletion = NO; pathAnim.repeatCount = MAXFLOAT; [shapeLayer addAnimation:pathAnim forKey:@"strokeEndAnim"];}
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注