iOS開(kāi)發(fā)之簡(jiǎn)單動(dòng)畫(huà)學(xué)習(xí)一

動(dòng)畫(huà)效果設(shè)計(jì)一直是iOS平臺(tái)的優(yōu)勢(shì),良好的動(dòng)效設(shè)計(jì)可以很好地提升用戶(hù)體驗(yàn),豐富app的展示,而動(dòng)畫(huà)則是動(dòng)效的基礎(chǔ)支撐。今天就來(lái)看一下簡(jiǎn)單的動(dòng)畫(huà)學(xué)習(xí)。
概念性的東西我就不做介紹了,我就直接上代碼(簡(jiǎn)單暴力,呵呵)

1.簡(jiǎn)單的縮放代碼

- (CAAnimation *)SetupScaleAnimation{
    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.duration = 3.0;
    scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];
    scaleAnimation.toValue = [NSNumber numberWithFloat:3.0];
    scaleAnimation.repeatCount = MAXFLOAT;
    scaleAnimation.autoreverses = YES;
    scaleAnimation.fillMode = kCAFillModeForwards;
    scaleAnimation.removedOnCompletion = NO;
    
    return scaleAnimation;
}

2.簡(jiǎn)單的移動(dòng)代碼

- (CAAnimation *)SetupMoveAnimation{
    CABasicAnimation *moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
    moveAnimation.fromValue = [NSValue valueWithCGPoint:_label.layer.position];
    moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(_label.layer.position.x, 667-60)];
    moveAnimation.autoreverses = YES;
    moveAnimation.duration = 3.0;
    return moveAnimation;
}

3.簡(jiǎn)單的旋轉(zhuǎn)代碼

- (CAAnimation *)SetupRotationAnimation{
    CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
    rotationAnimation.duration = 1.5;
    rotationAnimation.autoreverses = YES;
    rotationAnimation.repeatCount = MAXFLOAT;
    rotationAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
    rotationAnimation.toValue = [NSNumber numberWithFloat:2 * M_PI];
    rotationAnimation.fillMode = kCAFillModeBoth;
    return rotationAnimation;
}

4.動(dòng)畫(huà)組代碼

- (CAAnimation *)SetupGroupAnimation{
    CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
    groupAnimation.duration = 3.0;
    groupAnimation.animations = @[[self SetupScaleAnimation], [self SetupMoveAnimation], [self SetupRotationAnimation]];
    groupAnimation.autoreverses = YES;
    groupAnimation.repeatCount = MAXFLOAT;
    return groupAnimation;
}

調(diào)用代碼

- (void)SetupLayer{
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(150, 20, 100, 30)];
    label.text = @"哈哈哈";
    label.font = [UIFont boldSystemFontOfSize:12];
    label.textColor = [UIColor redColor];
    [self.view addSubview:label];
    _label = label;
    [_label.layer addAnimation:[self SetupScaleAnimation] forKey:@"scale"];
}

雖然這些很初級(jí),但是我之前一直不會(huì)怎么寫(xiě),都是網(wǎng)上搜代碼,所以我想學(xué)習(xí)一下,學(xué)習(xí)嘛,慢慢來(lái),急也急不來(lái),想做出很炫的動(dòng)畫(huà),是要日積月累的。插入一我的故事:之前為了5.20,作為一個(gè)碼農(nóng)的我,算是費(fèi)盡心思的取悅女朋友。學(xué)習(xí)的堅(jiān)持是需要?jiǎng)恿Φ?,取悅我心?ài)之人是我的動(dòng)力之一,其次還有就是我想做出更好的app,熟悉更多的知識(shí)。我想做出一個(gè)漂亮的動(dòng)效給她看,就以葫蘆畫(huà)瓢仿照著寫(xiě),終于有點(diǎn)成效,這就是我們碼農(nóng)的浪漫-用代碼成就浪漫,更勝一切浪漫。
demo的下載地址
該demo只是為了實(shí)現(xiàn)動(dòng)畫(huà)效果,代碼沒(méi)做封裝,望諒解,效果圖如下:

用代碼成就浪漫2.gif

學(xué)習(xí)筆記將持續(xù)更新。。。

最后編輯于
?著作權(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)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,741評(píng)論 25 709
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫(kù)、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,041評(píng)論 4 61
  • 親愛(ài)的自己,你好?,F(xiàn)在的你已經(jīng)20歲了,是一個(gè)即將步入社會(huì)的大三學(xué)生了。我不知道在未來(lái)的日子里你要經(jīng)歷什么。不...
    夢(mèng)戲筆談閱讀 242評(píng)論 0 0
  • 這么幾天過(guò)去了,我一直在思考我現(xiàn)在過(guò)的是什么日子和我想過(guò)什么日子。想明白了,心里總算透徹了不少,可還是有一點(diǎn)壓抑。...
    高松火鍋皮閱讀 291評(píng)論 0 0
  • 浪淘沙雙調(diào)小令 折柳贈(zèng)故人,且聽(tīng)風(fēng)吟 離人依依勸歡欣 也曾踱步芳叢,憶昔愿今 更惜別離時(shí),對(duì)酒談心 風(fēng)也微寒酒亦沁...
    零壹Zerone_閱讀 499評(píng)論 0 1

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