版本记录
版本号 | 时间 |
---|---|
V1.0 | 2017.12.12 |
前言
如果你细看了我前面写的有关动画的部分,就知道前面介绍了
CoreAnimation
、序列帧以及LOTAnimation
等很多动画方式,接下来几篇我们就以动画示例为线索,进行动画的讲解。相关代码已经上传至GitHub - 刀客传奇。感兴趣的可以看我写的前面几篇。
1. 动画示例(一) —— 一种外扩的简单动画
功能需求
实现抖动的那种动画,很多APP比如在做删除等操作时候,会进行抖动动画以提醒用户。
功能实现
下面还是先看代码。
#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];
[self.view addSubview:alertButton];
self.alertButton = alertButton;
}
#pragma mark - Object Private Function
- (void)alertButtonDidClick:(UIButton *)button
{
button.selected = !button.selected;
if (button.selected) {
srand([[NSDate date] timeIntervalSince1970]);
float rand=(float)random();
CFTimeInterval t=rand*0.0000000001;
[UIView animateWithDuration:0.1 delay:t options:0 animations:^
{
self.alertButton.transform = CGAffineTransformMakeRotation(-0.05);
} completion:^(BOOL finished)
{
[UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction animations:^
{
self.alertButton.transform = CGAffineTransformMakeRotation(0.05);
} completion:^(BOOL finished) {}
];
}];
}
else {
[UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState animations:^
{
self.alertButton.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
}
}
@end
功能效果
下面我们就看一下实现的效果。
后记
未完,待续~~~
网友评论