#import "MainViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.navigationController setNavigationBarHidden:YES];
UIButton *button = [UIButton buttonWithType:(UIButtonTypeSystem)];
button.backgroundColor = [UIColor cyanColor];
button.frame = CGRectMake(60, 120, 200, 80);
[button setTitle:@"开始动画" forState:(UIControlStateNormal)];
[button addTarget:self action:@selector(buttonChilke:) forControlEvents:(UIControlEventTouchUpInside)];
[self.view addSubview:button];
}
- (void)buttonChilke:(UIButton *)button
{
// UIView 动画
// 1. 最简单的动画实现
// 参数1: 动画执行一次需要的时间
// 参数2: 动画执行的内容 (写一个结果)
// [UIView animateWithDuration:10.0 animations:^{
//
// button.backgroundColor = [UIColor brownColor];
// button.frame = CGRectMake(0, 0, 320, 100);
// button.alpha = 0.5;
// }];
// 参数3: 动画执行结束之后 要执行的代码
// [UIView animateWithDuration:2.f animations:^{
//
// // 对动画的设置
//
// // 对动画有一个还原效果
// [UIView setAnimationRepeatAutoreverses:YES];
//
// // 动画重复的次数
// [UIView setAnimationRepeatCount:2.f];
//
// // 延迟几秒执行
// [UIView setAnimationDelay:1.0];
//
// // 动画运行的速度曲线
// [UIView setAnimationCurve:(UIViewAnimationCurveEaseIn)];
//
//
// button.backgroundColor = [UIColor blueColor];
// button.frame = CGRectMake(0, 0, 200, 200);
//
// } completion:^(BOOL finished) {
// NSLog(@"动画完毕");
// }];
// 3.
// 参数3: 动画的选项
// [UIView animateWithDuration:1.f delay:0 options:(UIViewAnimationOptionCurveEaseIn) animations:^{
//
// button.frame = CGRectMake(0, 0, 200, 200);
//
// } completion:nil];
// 4.
// [UIView animateWithDuration:1.f delay:0 usingSpringWithDamping:0.25 initialSpringVelocity:0.25 options:(UIViewAnimationOptionCurveEaseIn) animations:^{
// button.frame = CGRectMake(5, 5, 200, 200);
// } completion:nil];
// transition 动画
// [UIView transitionWithView:button duration:1.f options:(UIViewAnimationOptionTransitionFlipFromBottom) animations:^{
//
// button.bounds = CGRectMake(0, 0, 200, 200);
//
// } completion:nil];
// 把第一个视图 从父视图移除 把第二个视图 添加到父视图上
// UIView *view =[[UIView alloc] initWithFrame:(CGRectMake(50, 50 , 200, 200))];
// view.backgroundColor = [UIColor redColor];
//
// // 参数1: 要移除 的view
// // 参数2: 要添加的动画
// [UIView transitionFromView:button toView: view duration:1.f options:(UIViewAnimationOptionTransitionFlipFromLeft) completion:^(BOOL finished) {
//
// }];
// CAAnimation layer层动画
// CAPropertyAnimation 是一个抽象类
// 1. CABasicAnimation 使用
// CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform.scale.x"];
//
// // 从什么状态开始放大
// animation1.fromValue = [NSNumber numberWithInt:1];
// // 到什么状态结束
// animation1.toValue = [NSNumber numberWithInt:30];
// // 动画执行时间
// animation1.duration = 2.f;
// // 是否有一个恢复过程
// animation1.autoreverses = YES;
// animation1.repeatCount = NSIntegerMax;
//
[button.layer addAnimation:animation1 forKey:@"11"];
//
// CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//
// // 从什么状态开始放大
// animation2.fromValue = [NSNumber numberWithInt:0];
// // 到什么状态结束
// animation2.toValue = [NSNumber numberWithInt:M_PI * 2];
// // 动画执行时间
// animation2.duration = 2.f;
// // 是否有一个恢复过程
// animation2.autoreverses = YES;
// animation2.repeatCount = NSIntegerMax;
// // 组动画 将几个动画组合到一起, 同时执行.
// CAAnimationGroup *group = [CAAnimationGroup animation];
// //将动画 添加到组动画之中后 每个动画自己的设置都失效
// group.animations = @[animation1,animation2];
// group.duration = 3.f;
// group.autoreverses = YES;
// group.repeatCount = NSIntegerMax;
// [button.layer addAnimation:group forKey:@"11"];
// 关键帧动画
// CAKeyframeAnimation *keyFrameAni = [CAKeyframeAnimation animationWithKeyPath:@"position"];
// // 产生一个路径
// CGMutablePathRef path = CGPathCreateMutable();
// 设定一个初始点
// CGPathMoveToPoint(path, NULL, 100, 0);
// // 添加一个路过的点(添加一条直线的路径)
// CGPathAddLineToPoint(path, NULL, 20, 50);
// CGPathAddLineToPoint(path, NULL, 80, 90);
// CGPathAddLineToPoint(path, NULL, 100, 150);
// CGPathAddLineToPoint(path, NULL, 200, 200);
// CGPathAddLineToPoint(path, NULL, 300, 0);
// CGPathAddLineToPoint(path, NULL, 100, 30);
//
// // 添加一条曲线路径
// CGPathAddCurveToPoint(path, NULL, 10, 20, 100, 150, 100, 300);
// CGPathAddCurveToPoint(path, NULL, 100, 120, 10, 90, 130, 150);
// CGPathAddCurveToPoint(path, NULL, 120, 220, 120, 50, 80, 20);
//
// // 设置路径信息
// [keyFrameAni setPath:path];
// // 设置执行时间
// [keyFrameAni setDuration:5.f];
//
// [button.layer addAnimation:keyFrameAni forKey:@"11"];
CATransition *transition = [CATransition animation];
// 过度动画CATransiton 依靠type/Type改变动画效果
transition.duration = 1.f;
// 动画类型
[transition setType:@"cameraIrisHollowClose"];
// 动画方向
[transition setSubtype:kCATransitionFromLeft];
[button.layer addAnimation:transition forKey:@"111"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
/** type
*
* 各种动画效果 其中除了'fade', `moveIn', `push' , `reveal' ,其他属于私有的API.
* ↑↑↑上面四个可以分别使用'kCATransitionFade', 'kCATransitionMoveIn', 'kCATransitionPush', 'kCATransitionReveal'来调用.
* @"cube" 立方体翻滚效果
* @"moveIn" 新视图移到旧视图上面
* @"reveal" 显露效果(将旧视图移开,显示下面的新视图)
* @"fade" 交叉淡化过渡(不支持过渡方向) (默认为此效果)
* @"pageCurl" 向上翻一页
* @"pageUnCurl" 向下翻一页
* @"suckEffect" 收缩效果,类似系统最小化窗口时的神奇效果(不支持过渡方向)
* @"rippleEffect" 滴水效果,(不支持过渡方向)
* @"oglFlip" 上下左右翻转效果
* @"rotate" 旋转效果
* @"push"
* @"cameraIrisHollowOpen" 相机镜头打开效果(不支持过渡方向)
* @"cameraIrisHollowClose" 相机镜头关上效果(不支持过渡方向)
*/
@end