核心动画09-CATransition转场动画
// ViewController.m // 09-CATransition转场动画 #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UIImageView *imageView; @end @implementation ViewController static int i = 2; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // 转场代码 if (i == 4) { i = 1; } // 加载图片名称 NSString *imageN = [NSString stringWithFormat:@"%d",i]; _imageView.image = [UIImage imageNamed:imageN]; i++; // 转场动画 CATransition *anim = [CATransition animation]; anim.type = @"pageCurl"; anim.duration = 2; [_imageView.layer addAnimation:anim forKey:nil]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
10-动画组(了解)
// ViewController.m // 10-动画组(了解) #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UIView *redView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // 同时缩放,平移,旋转 CAAnimationGroup *group = [CAAnimationGroup animation]; CABasicAnimation *scale = [CABasicAnimation animation]; scale.keyPath = @"transform.scale"; scale.toValue = @0.5; CABasicAnimation *rotation = [CABasicAnimation animation]; rotation.keyPath = @"transform.rotation"; rotation.toValue = @(arc4random_uniform(M_PI)); CABasicAnimation *position = [CABasicAnimation animation]; position.keyPath = @"position"; position.toValue = [NSValue valueWithCGPoint:CGPointMake(arc4random_uniform(200), arc4random_uniform(200))]; group.animations = @[scale,rotation,position]; [_redView.layer addAnimation:group forKey:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
11-UIView和核心动画区别
// // ViewController.m // 10-UIView和核心动画区别 // // Created by xiaomage on 15/6/23. // Copyright (c) 2015年 xiaomage. All rights reserved. // #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UIView *redView; @end @implementation ViewController - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // CABasicAnimation *anim = [CABasicAnimation animation]; // // anim.keyPath = @"position"; // // anim.toValue = [NSValue valueWithCGPoint:CGPointMake(150, 400)]; // // // 注意:取消反弹代码必须放在图层添加动画之前。 // anim.removedOnCompletion = NO; // // anim.fillMode = kCAFillModeForwards; // // anim.delegate = self; // // [_redView.layer addAnimation:anim forKey:nil]; [UIView animateWithDuration:0.25 animations:^{ _redView.layer.position = CGPointMake(150, 400); } completion:^(BOOL finished) { NSLog(@"%@", NSStringFromCGPoint(_redView.layer.position)); }]; } // 注意:核心动画一切都是假象,并不会真实的改变图层的属性值,如果以后做动画的时候,不需要与用户交互,通常用核心动画(转场)。 // UIView动画必须通过修改属性的真实值,才有动画效果。 // 动画完成的时候调用 - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { NSLog(@"%@", NSStringFromCGPoint(_redView.layer.position)); } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSLog(@"%@", NSStringFromCGPoint(_redView.layer.position)); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
本人无商业用途,仅仅是学习做个笔记,特别鸣谢小马哥,学习了IOS,另日语学习内容有需要文本和音频请关注公众号:riyuxuexishuji