動(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)做封裝,望諒解,效果圖如下:

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