您的位置:首页 > 产品设计 > UI/UE

iOS学习笔记-080.核心动画06——UIView与核心动画对比

2017-06-16 01:33 483 查看
核心动画06UIView与核心动画对比
一基本说明

二代码
1 BlueViewm

2 RedViewm

3 ViewControllerm

三图示

四文字结果

五总结
1 UIView和核心动画区别

2 什么时候使用UIView的动画

3 什么场景使用核心动画最多

核心动画06——UIView与核心动画对比

一、基本说明

我们创建一个列子,界面上有两个UIView,蓝色的使用核心动画,红色使用UIView的动画

二、代码

2.1 BlueView.m

//
//  BlueView.m
//  03_UIView73_UIView与核心动画区别
//
//  Created by 杞文明 on 17/6/16.
//  Copyright © 2017年 杞文明. All rights reserved.
//

#import "BlueView.h"

@implementation BlueView

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
NSLog(@"___blueView___click: %@",NSStringFromCGRect(self.frame));
}

@end


2.2 RedView.m

//
//  RedVIew.m
//  03_UIView73_UIView与核心动画区别
//
//  Created by 杞文明 on 17/6/16.
//  Copyright © 2017年 杞文明. All rights reserved.
//

#import "RedVIew.h"

@implementation RedVIew

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
NSLog(@"___redView___click: %@",NSStringFromCGRect(self.frame));
}

@end


2.3 ViewController.m

//
//  ViewController.m
//  03_UIView73_UIView与核心动画区别
//
//  Created by 杞文明 on 17/6/16.
//  Copyright © 2017年 杞文明. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<CAAnimationDelegate>
@property (weak, nonatomic) IBOutlet UIView *blueView;
@property (weak, nonatomic) IBOutlet UIView *redView;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"=========");
[self coreAnim];
[self uiViewAnim];
}

//核心动画
-(void)coreAnim{
CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"position.y";
anim.toValue = @400;
anim.duration = 1;
anim.removedOnCompletion =NO;
anim.fillMode = kCAFillModeForwards;
anim.delegate = self;
[_blueView.layer addAnimation:anim forKey:nil];
}

//动画开始时执行
-(void)animationDidStart:(CAAnimation *)anim {
NSLog(@"___blueView___start: %@",NSStringFromCGRect(self.blueView.frame));
}

//动画结束
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
NSLog(@"___blueView_____end: %@",NSStringFromCGRect(self.blueView.frame));
}

//UIView动画
-(void)uiViewAnim{
[UIView animateWithDuration:0.2 animations:^{
NSLog(@"_redView___start: %@",NSStringFromCGRect(self.redView.frame));
self.redView.center = CGPointMake(270, 400);
} completion:^(BOOL finished) {
NSLog(@"_redView_____end: %@",NSStringFromCGRect(self.redView.frame));
}];
}
@end


三、图示



四、文字结果

2017-06-16 01:22:43.718 03_UIView73_UIView与核心动画区别[40479:1223929] ___blueView___click: {{61, 62}, {100, 100}}
2017-06-16 01:22:45.037 03_UIView73_UIView与核心动画区别[40479:1223929] ___redView___click: {{220, 62}, {100, 100}}
2017-06-16 01:22:46.169 03_UIView73_UIView与核心动画区别[40479:1223929] =========
2017-06-16 01:22:46.170 03_UIView73_UIView与核心动画区别[40479:1223929] _redView___start: {{220, 62}, {100, 100}}
2017-06-16 01:22:46.171 03_UIView73_UIView与核心动画区别[40479:1223929] ___blueView___start: {{61, 62}, {100, 100}}
2017-06-16 01:22:47.171 03_UIView73_UIView与核心动画区别[40479:1223929] ___blueView_____end: {{61, 62}, {100, 100}}
2017-06-16 01:22:48.172 03_UIView73_UIView与核心动画区别[40479:1223929] _redView_____end: {{220, 350}, {100, 100}}
2017-06-16 01:22:48.765 03_UIView73_UIView与核心动画区别[40479:1223929] ___redView___click: {{220, 350}, {100, 100}}
2017-06-16 01:22:51.143 03_UIView73_UIView与核心动画区别[40479:1223929] =========
2017-06-16 01:22:51.143 03_UIView73_UIView与核心动画区别[40479:1223929] _redView___start: {{220, 350}, {100, 100}}
2017-06-16 01:22:51.144 03_UIView73_UIView与核心动画区别[40479:1223929] ___blueView___start: {{61, 62}, {100, 100}}
2017-06-16 01:22:51.144 03_UIView73_UIView与核心动画区别[40479:1223929] _redView_____end: {{220, 350}, {100, 100}}
2017-06-16 01:22:52.145 03_UIView73_UIView与核心动画区别[40479:1223929] ___blueView_____end: {{61, 62}, {100, 100}}


五、总结

5.1 UIView和核心动画区别?

核心动画只能添加到CALayer

核心动画一切都是假象,并不会改变真实的值。

5.2 什么时候使用UIView的动画?

如果需要与用户交互就使用UIView的动画.

不需要与用户交互可以使用核心动画

5.3 什么场景使用核心动画最多?

在转场动画中,核心动画的类型比较多

根据一个路径做动画,只能用核心动画(帧动画)

动画组:同时做多个动画
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: