版本記錄
版本號(hào) | 時(shí)間 |
---|---|
V1.0 | 2017.12.12 |
前言
如果你細(xì)看了我前面寫的有關(guān)動(dòng)畫的部分,就知道前面介紹了
CoreAnimation
崇猫、序列幀以及LOTAnimation
等很多動(dòng)畫方式参萄,接下來幾篇我們就以動(dòng)畫示例為線索惭蟋,進(jìn)行動(dòng)畫的講解鹦肿。相關(guān)代碼已經(jīng)上傳至GitHub - 刀客傳奇。
功能需求
實(shí)現(xiàn)外擴(kuò)的那種動(dòng)畫玫镐,有點(diǎn)像水中掉落物體引起的漣漪一樣倒戏。
功能實(shí)現(xiàn)
下面我們就直接看代碼。
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) UIButton *alertButton;
@end
@implementation ViewController
#pragma mark - Override Base Function
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
UIButton *alertButton = [UIButton buttonWithType:UIButtonTypeCustom];
alertButton.frame = CGRectMake(self.view.bounds.size.width * 0.5 - 50.0, self.view.bounds.size.width * 0.5 - 50.0, 100.0, 100.0);
[alertButton addTarget:self action:@selector(alertButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
alertButton.backgroundColor = [UIColor redColor];
alertButton.layer.cornerRadius = 50.0;
alertButton.layer.masksToBounds = YES;
[self.view addSubview:alertButton];
self.alertButton = alertButton;
}
#pragma mark - Object Private Function
- (void)alertButtonDidClick:(UIButton *)button
{
CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = 1.0;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.8, 0.8, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
animation.values = values;
[self.alertButton.layer addAnimation:animation forKey:nil];
}
@end
功能效果
下面我們就看一下實(shí)現(xiàn)的效果恐似。
后記
未完杜跷,待續(xù)~~~