Block动画和spring动画
1 #import "BlockViewController.h" 2 3 @interface BlockViewController () 4 @property (weak, nonatomic) IBOutlet UIImageView *yuanyuanImageView; 5 6 @end 7 8 @implementation BlockViewController 9 10 - (void)viewDidLoad { 11 [super viewDidLoad]; 12 #pragma mark - UIView Block 的简单动画 13 //第一个参数:设置时长, 14 //第二个参数:设置动画要实现的效果 15 //第三个参数:完成动画的时候所做的事情 16 // [UIView animateWithDuration:2 animations:^{ 17 // //动画实现的效果改变imageView的中心位置 18 // NSLog(@"start"); 19 // self.yuanyuanImageView.center = self.view.center; 20 //// self.yuanyuanImageView.alpha = 0.3; 21 // 22 // } completion:^(BOOL finished) { 23 // NSLog(@"finished"); 24 // 25 // }]; 26 #pragma mark - UIView Block 的复杂动画 27 //1.动画时长,2.动画延迟时间,3.动画效果枚举值,4.实现的动画效果,5.完成动画 28 29 // [UIView animateWithDuration:3 delay:2 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 30 // NSLog(@"start"); 31 // self.yuanyuanImageView.center = self.view.center; 32 // } completion:^(BOOL finished) { 33 // NSLog(@"finished"); 34 // }]; 35 #pragma mark - Block的关键帧动画 36 //1.动画时长,2.动画延迟时间,3.动画效果枚举值,4.实现的动画效果,5.完成动画 37 // [UIView animateKeyframesWithDuration:3 delay:2 options:UIViewKeyframeAnimationOptionRepeat animations:^{ 38 // 39 // //在这个Block里边添加一个关键帧动画 40 // //1.帧动画开始时间,2.持续时间,3. 41 // [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.5 animations:^{ 42 // self.yuanyuanImageView.center = self.view.center; 43 // }]; 44 // } completion:^(BOOL finished) { 45 // 46 // }]; 47 48 } 49 - (IBAction)esayBlock:(UIButton *)sender { 50 [UIView animateWithDuration:2 animations:^{ 51 NSLog(@"start"); 52 self.yuanyuanImageView.center = self.view.center; 53 } completion:^(BOOL finished) { 54 55 }]; 56 } 57 - (IBAction)complexBlock:(UIButton *)sender { 58 [UIView animateWithDuration:2 delay:2 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 59 self.yuanyuanImageView.center = self.view.center; 60 } completion:^(BOOL finished) { 61 62 }]; 63 64 } 65 - (IBAction)keyBlock:(UIButton *)sender { 66 [UIView animateKeyframesWithDuration:2 delay:2 options:UIViewKeyframeAnimationOptionRepeat animations:^{ 67 [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.5 animations:^{ 68 NSLog(@"start"); 69 self.yuanyuanImageView.center = self.view.center; 70 }]; 71 } completion:^(BOOL finished) { 72 NSLog(@"finished"); 73 }]; 74 // [UIView animateKeyframesWithDuration:3 delay:2 options:UIViewKeyframeAnimationOptionRepeat animations:^{ 75 // 76 // //在这个Block里边添加一个关键帧动画 77 // //1.帧动画开始时间,2.持续时间,3. 78 // [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.5 animations:^{ 79 // self.yuanyuanImageView.center = self.view.center; 80 // }]; 81 // } completion:^(BOOL finished) { 82 // 83 // }]; 84 }
2.spring
1 #import "SpringViewController.h" 2 3 @interface SpringViewController () 4 @property (weak, nonatomic) IBOutlet UIImageView *imageView; 5 6 @end 7 8 @implementation SpringViewController 9 10 - (void)viewDidLoad { 11 [super viewDidLoad]; 12 //1.动画时长 2.延迟时长 3.类似于弹簧的效果(0-1) 4.初始的速度 5.动画过渡效果 6. 开始动画 7.完成动画 13 14 [UIView animateWithDuration:2 delay:2 usingSpringWithDamping:0.8 initialSpringVelocity:18 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 15 self.imageView.center = self.view.center; 16 } completion:^(BOOL finished) { 17 18 }]; 19 20 }