1 // 2 // ViewController.m 3 // CAAnimationAndViewAnimation 4 // 5 // Created by ys on 15/11/22. 6 // Copyright (c) 2015年 ys. All rights reserved. 7 // 8 9 #import "ViewController.h" 10 11 @interface ViewController () 12 @property (weak, nonatomic) IBOutlet UIView *blackView; 13 14 @end 15 16 @implementation ViewController 17 18 - (void)viewDidLoad { 19 [super viewDidLoad]; 20 } 21 22 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 23 { 24 // [self diyCACoreAnimation]; 25 // [self viewAnimation1]; 26 // [self viewAnimation2]; 27 [self viewAnimation3]; 28 29 } 30 /** 31 * 核心动画的问题在于 1.其直接操作layer层,和view层比不够面向对象. 32 * 2.layer的属性均没有改变.图层动画都是假象, 在动画执行过程中, 图层的position属性一直都没有变过 33 * 因此在实际开发中,除非某些效果难以达到,一般都是使用view实现动画 34 */ 35 -(void)diyCACoreAnimation 36 { 37 CABasicAnimation *anim = [CABasicAnimation animation]; 38 anim.keyPath = @"position"; 39 anim.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 200)]; 40 anim.duration = 0.5; 41 anim.removedOnCompletion = NO; 42 anim.fillMode = kCAFillModeForwards; 43 anim.delegate = self; 44 [self.blackView.layer addAnimation:anim forKey:nil]; 45 46 } 47 48 -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag 49 { 50 //diyCACoreAnimation动画结束后打印一下发现图层的position属性一直都没有变过 51 NSLog(@"%@",NSStringFromCGPoint(self.blackView.layer.position)); 52 } 53 54 -(void)viewAnimation1 55 { 56 [UIView beginAnimations:nil context:nil]; 57 self.blackView.center = CGPointMake(200, 200); 58 [UIView commitAnimations]; 59 NSLog(@"%@",NSStringFromCGPoint(self.blackView.center)); 60 } 61 62 -(void)viewAnimation2 63 { 64 [UIView animateWithDuration:1.0 animations:^{ 65 self.blackView.center = CGPointMake(200, 200); 66 } completion:^(BOOL finished) { 67 NSLog(@"%@",NSStringFromCGPoint(self.blackView.center)); 68 }]; 69 } 70 71 -(void)viewAnimation3 72 { 73 [UIView transitionWithView:self.blackView duration:10 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{ 74 } completion:^(BOOL finished) { 75 }]; 76 } 77 @end
原文:http://www.cnblogs.com/yangshun-work/p/4986095.html