首先看下效果展示:

動(dòng)畫(huà).gif
Core Animation(核心動(dòng)畫(huà))是一組功能強(qiáng)大、效果華麗的動(dòng)畫(huà)API,無(wú)論在iOS系統(tǒng)或者在你開(kāi)發(fā)的App中,都有大量應(yīng)用。
樓主簡(jiǎn)單的利用UIBezierPath繪畫(huà)圓,然后利用CABasicAnimation的opacity調(diào)整視圖的透明度,然后利用CABasicAnimation的transform.scale來(lái)實(shí)現(xiàn)圓的放大縮小,如果想要了解更多傳送門:
http://www.imlifengfeng.com/blog/?p=548
廢話不多所上代碼
基本都是通過(guò)懶加載實(shí)現(xiàn)
創(chuàng)建CAShapeLayer
- (CAShapeLayer *)shapeLayer{
if (_shapeLayer==nil) {
_shapeLayer = [CAShapeLayer layer];
_shapeLayer.frame = CGRectMake(100, 100, 100, 100);
_shapeLayer.fillColor = [UIColor blueColor].CGColor;
_shapeLayer.strokeColor = [UIColor blackColor].CGColor;
//通過(guò)貝塞爾曲線繪制圓
CGFloat startAngle = 0.0;
CGFloat endAngle = M_PI *2;
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(50, 50) radius:50 startAngle:startAngle endAngle:endAngle clockwise:YES];
_shapeLayer.path = bezierPath.CGPath;
}
return _shapeLayer;
}
添加動(dòng)畫(huà)組這里用到CAAnimationGroup
- (CAAnimationGroup *)animaGroup{
if (_animaGroup == nil) {
CABasicAnimation * _opacityAnima = [CABasicAnimation animationWithKeyPath:@"opacity"];
_opacityAnima.fromValue = @(0.7);
_opacityAnima.toValue = @(0.3);
CABasicAnimation *expandAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
expandAnimation.fromValue = [NSNumber numberWithFloat:1]; // 開(kāi)始時(shí)的倍率
expandAnimation.toValue = [NSNumber numberWithFloat:1.5]; // 結(jié)束時(shí)的倍率
_animaGroup = [CAAnimationGroup animation];
_animaGroup.animations = @[ expandAnimation,_opacityAnima];
_animaGroup.duration = 3;
_animaGroup.repeatCount = HUGE;
_animaGroup.autoreverses = YES;
}
return _animaGroup;
}
具體里面的屬性可以點(diǎn)擊上文鏈接了解不多解釋,只實(shí)現(xiàn)
動(dòng)畫(huà)開(kāi)始、停止方法
/Start Animation
- (void)startAnimation{
[self.layer addSublayer:self.shapeLayer];
[self.shapeLayer addAnimation:self.animaGroup forKey:@"scaleGroup"];
}
//Stop Animation
- (void)stopAnimation{
if (_shapeLayer) {
[self.shapeLayer removeAllAnimations];
[self.shapeLayer removeFromSuperlayer];
}
}
代碼地址:https://github.com/lanjiaoli/Animation
有不足的地方大家多多指出,謝謝