UI Animation 动画效果

  1 - (void)buttonClicked:(UIButton *)button  
  2 {  
  3     // UIView 动画  
  4     // 1.最简单的动画实现  
  5     // 参数1:动画执行一次需要的时间  
  6     // 参数2:动画执行的内容(写动画执行的结果)  
  7 //    [UIView animateWithDuration:10.0 animations:^{  
  8 //        button.alpha = 0.38;  
  9 //        button.backgroundColor = [UIColor blueColor];  
 10 //        button.frame = CGRectMake(0, 0, 320, 100);  
 11 //    }];  
 12       
 13       
 14       
 15       
 16     // 参数3:动画执行结束后 要执行的代码  
 17 //    [UIView animateWithDuration:1.f animations:^{  
 18 //          
 19 //        // 对动画本身设置  
 20 //          
 21 //        // 可以给动画一个还原效果  
 22 //        [UIView setAnimationRepeatAutoreverses:YES];  
 23 //        // 动画重复的次数  
 24 //        [UIView setAnimationRepeatCount:1.25];  
 25 //        // 动画延迟几秒执行  
 26 //       // [UIView setAnimationDelay:1.0];  
 27 //        // 动画运行的速度曲线  
 28 //        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];  
 29 //          
 30 //        button.backgroundColor = [UIColor blueColor];  
 31 //        button.bounds = CGRectMake(0, 0, 200, 200);  
 32 //    } completion:^(BOOL finished) {  
 33 //        NSLog(@"动画完毕");  
 34 //    }];  
 35       
 36       
 37       
 38     // 3.  
 39       
 40     // 参数3:动画的选项 在这里一般写 速度曲线  
 41 //    [UIView animateKeyframesWithDuration:1.f delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{  
 42 //        button.frame = CGRectMake(0, 0, 200, 200);  
 43 //    } completion:nil];  
 44       
 45       
 46       
 47     //4.  
 48       
 49 //    [UIView animateWithDuration:1.f delay:0 usingSpringWithDamping:0.05 initialSpringVelocity:0.4 options:UIViewAnimationOptionCurveEaseIn animations:^{  
 50 //        button.frame = CGRectMake(0, 0, 200, 200);  
 51 //    } completion:nil];  
 52   
 53       
 54       
 55     // transition动画  
 56       
 57 //    [UIView transitionWithView:button duration:1.f options:UIViewAnimationOptionTransitionCurlDown animations:^{  
 58 //        button.frame = CGRectMake(0, 0, 200, 200);  
 59 //    } completion:nil];  
 60       
 61       
 62       
 63     // 把第一个视图移除 把第二个视图 添加到父视图上  
 64       
 65 //    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];  
 66 //    view.backgroundColor = [UIColor blueColor];  
 67 //    // 参数1;要移除的view  
 68 //    // 参数2:要添加的view  
 69 //    [UIView transitionFromView:button toView:view duration:1.f options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {  
 70 //      
 71 //    }];  
 72       
 73       
 74       
 75     // CAAnimation layer层动画  
 76       
 77     // CAPropertyAnimation 是一个抽象类  
 78     // 1. CABasicAnimation 的使用  
 79       
 80 //    CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];  
 81 //    // 从什么状态开始放大  
 82 //    animation1.fromValue = [NSNumber numberWithInt:1];  
 83 //    // 到什么状态结束  
 84 //    animation1.toValue = [NSNumber numberWithInt:3];  
 85 //    // 动画执行的时间  
 86 //    animation1.duration = 1.f;  
 87 //    // 是否有一个恢复  
 88 //    animation1.autoreverses = YES;  
 89 //    animation1.repeatCount = NSIntegerMax;  
 90 //      
 91 //      
 92 //    CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];  
 93 //      
 94 //    // 从什么状态开始放大  
 95 //    animation2.fromValue = [NSNumber numberWithInt:1];  
 96 //    // 到什么状态结束  
 97 //    animation2.toValue = [NSNumber numberWithInt:M_PI * 2];  
 98 //    // 动画执行的时间  
 99 //    animation2.duration = 2.f;  
100 //    // 是否有一个恢复  
101 ////    animation2.autoreverses = YES;  
102 //    animation2.repeatCount = NSIntegerMax;  
103 //      
104 //      
105 //      
106 //    // 组动画 将几个动画组合到一起 同时执行  
107 //      
108 //    CAAnimationGroup *group = [CAAnimationGroup animation];  
109 //    group.animations = @[animation1,animation2];  
110 //    // 将动画 添加到组动画之后 每个动画自己的设置将失效  
111 //    group.duration = 3.f;  
112 //    group.autoreverses = YES;  
113 //    group.repeatCount = NSIntegerMax;  
114 //      
115 //    [button.layer addAnimation:group forKey:@"111"];  
116 //      
117 //      
118 //      
119 //    [button.layer addAnimation:animation2 forKey:@"111"];  
120       
121       
122       
123       
124 //    // 关键帧动画  
125 //    CAKeyframeAnimation *keyFrameAni = [CAKeyframeAnimation animationWithKeyPath:@"position"];  
126 //      
127 //    // 产生一个路径  
128 //    CGMutablePathRef path = CGPathCreateMutable();  
129 //    // 设定一个初始点  
130 //    CGPathMoveToPoint(path, nil, 100, 100);  
131 //      
132 //    // 添加一个路过的点(添加一条直线的路径)  
133 //    CGPathAddLineToPoint(path, NULL, 200, 100);  
134 //    CGPathAddLineToPoint(path, NULL, 300, 0);  
135 //    CGPathAddLineToPoint(path, NULL, 10, 200);  
136 //    CGPathAddLineToPoint(path, NULL, 30, 0);  
137 //    CGPathAddLineToPoint(path, NULL, 150, 40);  
138 //    CGPathAddLineToPoint(path, NULL, 300, 0);  
139 //      
140 //      
141 //    // 添加一条曲线路径  
142 //    CGPathAddCurveToPoint(path, NULL, 10, 20, 100, 300, 150, 100);  
143 //    CGPathAddCurveToPoint(path, NULL, 100, 150, 100, 0, 150, 100);  
144 //    CGPathAddCurveToPoint(path, NULL, 120, 230, 105, 542, 10, 10);  
145 //      
146 //    // 设置路径信息  
147 //    [keyFrameAni setPath:path];  
148 //    // 设置执行时间  
149 //    [keyFrameAni setDuration:5.f];  
150 //      
151 //    [button.layer addAnimation:keyFrameAni forKey:@"222"];  
152       
153       
154       
155       // 过渡 变形  
156 //    CATransition *transition = [CATransition animation];  
157 //      
158 //    // 过渡动画CATransition 依靠type/subType改变动画效果  
159 //    transition.duration = 2.f;  
160 //      
161 //    // 动画类型  
162 //    //[transition setType:kCATransitionMoveIn];  
163 //    [transition setType:@"cameraIrisHollowClose"];  
164 //    // 动画方向  
165 //    [transition setSubtype:kCATransitionFromLeft];  
166 //      
167 //    [button.layer addAnimation:transition forKey:@"333"];  
168 }  

 

posted @ 2016-06-06 15:40  超级马力  阅读(634)  评论(0编辑  收藏  举报