动画学习2

来源:互联网 发布:洗照片怎么在淘宝里收 编辑:程序博客网 时间:2024/05/20 17:10

1.CATransation 事务类(我也不知道什么意思..) ,可以对多个layer的属性同时进行修改.它分隐式事务,和显式事务.
例子:通过CATransation来使一个view随着触摸移动

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{    //    method1    //    layer随着触摸移动    [CATransaction begin];    [CATransaction flush];    //    关闭动画    //    [CATransaction setDisableActions:YES];    [CATransaction setAnimationDuration:1.0];    [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];    self.colorLayer.position = [[touches anyObject]locationInView:self.view];    //    提交动画    [CATransaction commit];    //  method2    //[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{    //self.colorView.center = [[touches anyObject]locationInView:self.view];    //    } completion:NULL];}

2.CATransition 转场动画
添加一个imageView,给imageView添加手势,点击时出现动画效果

-(void)myTap{    CATransition * animation = [CATransition animation];    [animation setDuration:3.0];//    枚举    [animation setFillMode:kCAFillModeRemoved];    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];//    波纹,rippleEffect是系统的字符串,具体有:cameraIris,cube,fade,moveIn,oglFilp,pageCurl, pageUnCurl ,push,reveal,rippleEffect,suckEffect 等等//  [animation setType:@"rippleEffect"];    [animation setType:@"cameraIris"];    [animation setSubtype:kCATransitionFromTop];    animation.delegate = self;    [iv.layer addAnimation:animation forKey:nil];}
0 0
原创粉丝点击