-
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.// UIView 动画
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(0, 200, 200, 100);
button.backgroundColor = [UIColor redColor];[button addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void)btnAction:(UIButton *)button{
NSLog(@"点击");
// 1. 最简单的UIView动画的实现
//参数1: 动画持续的时间
// 参数2 : 动画执行的最终结果
[UIView animateWithDuration:1 animations:^{
/// 动画执行后View的样子
// frame, center, bounds, backgroundColor, alpha, hidden, transform
button.frame = CGRectMake(0, 64, 100, 100);
button.backgroundColor = [UIColor greenColor];
}];
// 2.
// 参数3: 动画完成后要做的工作
[UIView animateWithDuration:1 animations:^{
button.backgroundColor = [UIColor yellowColor];
} completion:^(BOOL finished) {
NSLog(@"爆炸了");
[UIView animateWithDuration:3 animations:^{
button.backgroundColor = [UIColor redColor];
}];
}];
// 3.option mode style type 出现这几个关键字类型基本都是枚举
[UIView animateWithDuration:1 delay:2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
button.frame = CGRectMake(0, 64, 100, 100);
} completion:^(BOOL finished) {
NSLog(@"OVER");
}];
// 4. // 弹动效果
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.1 initialSpringVelocity:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
button.frame = CGRectMake(0, 64, 100, 100);
} completion:^(BOOL finished) {
}];
// 5. pop 第三方动画框架
[UIView animateWithDuration:1 animations:^{
// 设置动画的相关属性
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:2.5]; // 重复次数
[UIView setAnimationRepeatCount:NSIntegerMax]; // 无数次NSIntegerMax;
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; // 设置速度.两边慢, 中间快.
button.frame= CGRectMake(0, 64, 100, 100);
}];