#pragma mark - CAAnimation类、实现动画 #pragma mark ** CABasicAnimation 动画 - (IBAction)handleCABasicAnimation:(id)sender { /* 创建动画类的对象 */ CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; /*初始值*/ basic.fromValue = [NSNumber numberWithInt:0]; basic.toValue = [NSNumber numberWithInt:3]; /* 动画的相关设置 */ basic.duration = 3; basic.repeatCount = NSIntegerMax; /* 添加到相关的View的layer属性上 */ [self.myView.layer addAnimation:basic forKey:@"basic"]; } #pragma mark - **CAAinmationGroup 动画 - (IBAction)handleCAAnimationCroup:(id)sender { /**创建多个Animation对象*/ CABasicAnimation *b1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"]; b1.fromValue = [NSNumber numberWithInt:1]; b1.toValue = [NSNumber numberWithInt:200]; CABasicAnimation *b2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"]; b2.fromValue = [NSNumber numberWithInt:0]; b1.toValue = [NSNumber numberWithInt:100]; CABasicAnimation *b3 = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; b3.fromValue = [NSNumber numberWithInt:100]; b3.toValue = [NSNumber numberWithInt:200]; /* 创建动画组对象*/ CAAnimationGroup *aGroup = [[CAAnimationGroup alloc]init]; /* 设置组对象的动画数组属性 */ aGroup.animations = @[b1,b2,b3]; /* 动画相关设置 */ aGroup.duration = 3; aGroup.repeatCount = NSIntegerMax; /* 添加到相关View的layer属性上*/ [self.myView.layer addAnimation:aGroup forKey:@"aGroup"]; } #pragma mark - CAKeyframeAnimation 动画 - (IBAction)handleCAKeyframeAnimation:(id)sender { /* 创建动画对象 */ //CAKeyframeAnimation *keyA = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation"]; CAKeyframeAnimation *keyA = [CAKeyframeAnimation animationWithKeyPath:@"position"]; /* 设置动画对象的path属性(对象要沿着path移动)*/ /* 创建CGPathRef结构体*/ CGMutablePathRef path = CGPathCreateMutable(); /* 指定path的初始的位置 */ CGAffineTransform t = self.redView.transform; CGPathMoveToPoint(path, &t, self.redView.center.x, self.redView.center.y); // /* Path添加点坐标(直线) */ // CGPathAddLineToPoint (path, &t, 100, 100); // CGPathAddLineToPoint(path, &t, 300, 100); /* 添加贝塞尔曲线 */ CGPathAddCurveToPoint(path, &t, self.redView.center.x, self.redView.center.y, 100, 80, 300, 100); /* Path设置动画对象的属性 */ keyA.path = path; keyA.duration = 3; keyA.repeatCount = 3; /* 相应地View的layer属性添加动画 */ [self.redView.layer addAnimation:keyA forKey:@"keyA"]; } #pragma mark **CATransition 动画 - (IBAction)handleCATranslation:(id)sender { /* 创建对象 */ CATransition *transtition = [CATransition animation]; /* 设置相关的属性 */ //transtition.type = kCATransitionMoveIn; transtition.type = @"cube"; transtition.repeatCount = NSIntegerMax; /* View的layer添加动画 */ transtition.duration = 3; [self.myView.layer addAnimation:transtition forKey:@"transition"]; } /** type * * 各种动画效果 其中除了'fade', `moveIn', `push' , `reveal' ,其他属于私有的API. * ↑↑↑上面四个可以分别使用'kCATransitionFade', 'kCATransitionMoveIn', 'kCATransitionPush', 'kCATransitionReveal'来调用. * @"cube" 立方体翻滚效果 * @"moveIn" 新视图移到旧视图上面 * @"reveal" 显露效果(将旧视图移开,显示下面的新视图) * @"fade" 交叉淡化过渡(不支持过渡方向) (默认为此效果) * @"pageCurl" 向上翻一页 * @"pageUnCurl" 向下翻一页 * @"suckEffect" 收缩效果,类似系统最小化窗口时的神奇效果(不支持过渡方向) * @"rippleEffect" 滴水效果,(不支持过渡方向) * @"oglFlip" 上下左右翻转效果 * @"rotate" 旋转效果 * @"push" * @"cameraIrisHollowOpen" 相机镜头打开效果(不支持过渡方向) * @"cameraIrisHollowClose" 相机镜头关上效果(不支持过渡方向) */ /** type * * kCATransitionFade 交叉淡化过渡 * kCATransitionMoveIn 新视图移到旧视图上面 * kCATransitionPush 新视图把旧视图推出去 * kCATransitionReveal 将旧视图移开,显示下面的新视图 */