iOS 關(guān)于千聊錄音動(dòng)畫(huà)的簡(jiǎn)單實(shí)現(xiàn)

首先看下效果展示:


動(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à)圓,然后利用CABasicAnimationopacity調(diào)整視圖的透明度,然后利用CABasicAnimationtransform.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
有不足的地方大家多多指出,謝謝

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容