- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
__weak typeof (self) pSelf = self;
// 第一个参数代表的是动漫的时间
// block块里面代表的是执行的动画
[UIView animateWithDuration:2.0f animations:^{
pSelf.myView.frame = CGRectMake(100, 100, 200, 200);
pSelf.myView.backgroundColor = [UIColor purpleColor];
//改变bounds 的时候也可以执行动画, 但是是以示图的cente为中心向两边扩充
pSelf.myView.bounds = CGRectMake(0, 0, 200, 200);
pSelf.myView.center = pSelf.view.center;
pSelf.myView.alpha = 0.1;
}];
//第一个参数代表时间
//第二个block块代表执行的动画
//第二个block快代表动画完成
[UIView animateWithDuration:1.0f animations:^{
pSelf.myView.backgroundColor = [UIColor grayColor];
}completion:^(BOOL finished) {
// 这里的代码 不会被当作动画执行
pSelf.myView.backgroundColor = [UIColor redColor];
}];
// 第一个参数 代表的是执行时间
// 第二个参数 代表的是延迟多久执行
// 第三个参数 代表的是动画的一些特效
[UIView animateWithDuration:2.0f delay:1.0f options:UIViewAnimationOptionRepeat animations:^{
pSelf.myView.backgroundColor = [UIColor purpleColor];
} completion:^(BOOL finished) {
pSelf.myView.backgroundColor = [UIColor redColor];
}];
//usingSpringWithDamping代表的是阻尼系数, 取值范围是0~1.值越大 效果越小; 值越小 效果越明显
[UIView animateWithDuration:1.0f delay:0 usingSpringWithDamping:0.01 initialSpringVelocity:25 options:UIViewAnimationOptionRepeat animations:^{
pSelf.myView.frame = CGRectMake(200, 200, 100, 100);
} completion:^(BOOL finished) {
}];
//
//第一个参数: 代表的是动画的名字
//第二个参数: 代表的是一个上下文相关的,目前没有用 以后不确定
[ UIView beginAnimations:nil context:nil];
// 从当前状态开始
[UIView setAnimationBeginsFromCurrentState:YES];
//设置动画在出现和结束的时候的一些特效
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
//设置动画的执行时间
[UIView setAnimationDuration:3.0f];
// 设置动画的重复次数
[UIView setAnimationRepeatCount:100];
// 设置动画代理人
[UIView setAnimationDelegate:self];
//动画将要开始 会执行sel方法
// UIView setAnimationWillStartSelector:@selector(selector);
//动画将要开始 会执行sel方法
self.myView.frame = CGRectMake(100, 100, 200, 200);
// 改交动画 去执行动画
[UIView commitAnimations];
// 第一个参数 要变没的view
//第二个参数 要变出来的view
// 第三个参数 要变出来的动作
// 第四个参数
[UIView transitionWithView:self.view duration:1.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
if (pSelf.controllerView.superview == nil) {
[pSelf.tableView removeFromSuperview];
[pSelf.view addSubview:_controllerView];
}else{
[pSelf.controllerView removeFromSuperview];
[pSelf.view addSubview:_tableView];
}
} completion:^(BOOL finished) {
}];
- (void)viewDidLoad {
[super viewDidLoad];
self.myView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
self.myView.backgroundColor = [UIColor redColor];
[self.view addSubview:self.myView];
//核心动画
//可以path的参数 必须时候在calayer类里面的属性 而且在属性的注释里面是有 animatable 这个单词的才可以使用
// CABasicAnimation *BA = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
//动画持续时间
// BA.duration = 2.0f;
//设置动画开始值
// BA.fromValue = @(0);
//设置动画结束的值
// BA.toValue = @(M_PI / 2 );
//核心动画一定要添加到layer里面
//第一个参数 代表的是哪一部分动画
//第二个参数 代表的随便的一个key值 这个可以可以任何值 会在移除的时候用
// [_myView.layer addAnimation:BA forKey:@"base"];
//相关的一组动画
// CAKeyframeAnimation *keyFA = [CAKeyframeAnimation animationWithKeyPath:@"position"];
// // keyFA.duration = 5.0f;
// //重复次数
// // keyFA.repeatCount = 10;
// //如果设置的属性是结构体类型的, 要把结构体构建成一个nsvalue
// NSValue *value = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
// NSValue *value2 = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
// NSValue *value3 = [NSValue valueWithCGPoint:CGPointMake(0, 300)];
// NSValue *value4 = [NSValue valueWithCGPoint:CGPointMake(300, 400)];
// NSValue *value5 = [NSValue valueWithCGPoint:CGPointMake(0, 400)];
//
// keyFA.values = @[value,value2,value3,value4,value5];
// [self.myView.layer addAnimation:keyFA forKey:@"base1"];
//
//
// CAKeyframeAnimation *keyFA1 = [CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"];
// keyFA1.duration = 20;
// keyFA1.repeatCount = 10;
// id color1 = (id)[UIColor redColor].CGColor;
// id color2 = (id)[UIColor blueColor].CGColor;
// id color3 = (id)[UIColor purpleColor].CGColor;
// id color4 = (id)[UIColor redColor].CGColor;
// id color5 = (id)[UIColor blueColor].CGColor;
// id color6 = (id)[UIColor blackColor].CGColor;
// id color7 = (id)[UIColor yellowColor].CGColor;
// id color8 = (id)[UIColor whiteColor].CGColor;
//
//keyFA1.values = @[color1,color2,color3,color4,color5,color6,color7,color8];
// [self.myView.layer addAnimation:keyFA1 forKey:@"base2"];
//播放一组没有相关联的动画
// CAAnimationGroup *group = [CAAnimationGroup animation];
// group.animations = @[keyFA,keyFA1];
// group.duration = 10.0;
// group.repeatCount = 10;
//
// [self.myView.layer addAnimation:group forKey:@"base2"];
//
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ //视图切换的效果
CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
//代表的是 动画的效果
transition.type = @"suckEffect";
//代表的是 动画的方向
transition.subtype = kCATransitionFromBottom;
[self.myView.layer addAnimation:transition forKey:@"key"];
}
学习的一些知识点 记录下来!请勿喷。有不对的地方请大神留言指导!