A GUIDE TO IOS ANIMATION 2.0----学习笔记
来源:互联网 发布:如何测试网络的连通性 编辑:程序博客网 时间:2024/04/28 22:16
此博客记录学习A GUIDE TO IOS ANIMATION 2.0这本书的过程中的一些心得,也是个人一些经验
首先,第一章玩转贝塞尔曲线.之前只接触到的画图方法是先创建一个类,继承自UIView,在这个类中重写 -(void)drawRect:(CGRect)rect方法,可实现画图.其代码实现分三步:1.获得上下文 2.拼接路径(绘制图形) 3.渲染图形
在本章中将学习中将学习一种新的画图方法,原理类似:创建一个继承CALayer的类,然后在这个类中重写- (void)drawInContext:(CGContextRef)ctx方法来实现画图,下面是代码实现
首先创建一个创建一个继承自CALayer的类
#import "LMYAnimationLayer.h"@implementation LMYAnimationLayer- (void)drawInContext:(CGContextRef)ctx { //画一个圆,可用两种方法,下面两种方法实现的效果相同 //用画椭圆的方式,要注意的是第二个参数的rect的x和y不是圆心的位置, //而是约束这个圆的外接矩形的frame种的值 // CGContextAddEllipseInRect(ctx, CGRectMake(0, 0, 100, 100)); //直接用画圆的方法 CGContextAddArc(ctx, 160, 160, 50, 0, M_PI * 2, 1); //设置颜色 CGContextSetRGBFillColor(ctx, 0, 0, 1, 1); //渲染 CGContextFillPath(ctx);}@end
然后创建一个自定义的View,重写initWithFrame:方法,添加上面创建的layer,最终在控制其中添加这个自定义的view,即可显示,代码如下
- (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.aniLayer = [LMYAnimationLayer layer]; //在此处之后就可以调用setNeedsDisplay方法 self.aniLayer.frame = self.bounds; self.aniLayer.contentsScale = [UIScreen mainScreen].scale; self.aniLayer.backgroundColor = [UIColor whiteColor].CGColor; [self.layer addSublayer:self.aniLayer]; [self.aniLayer setNeedsDisplay]; } return self;}@end最后在控制器中添加
#import "LMYAnimationView.h"#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; LMYAnimationView *testView = [[LMYAnimationView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 320 / 2, self.view.frame.size.height / 2 - 320 / 2, 320, 320)]; testView.backgroundColor = [UIColor orangeColor]; [self.view addSubview:testView];}@end到此,准备工作已经大体完成.
0 0
- A GUIDE TO IOS ANIMATION 2.0----学习笔记
- 读《A Guide To iOS Animation》-AnimatedCircleDemo
- 个人Core Animation Programming Guide 学习笔记
- IOS Animation学习笔记
- Guide to Computer Animation
- A guide to Matlab for Beginners and Experienced Users——学习笔记【1】
- A guide to Matlab for Beginners and Experienced Users——学习笔记【2】
- 《A Programmer's Guide to Data Mining》第二章学习笔记
- IOS学习笔记(三)UIView animation
- iOS学习笔记60-IOS动画Core Animation详解
- Beej's Guide to Network Programming 学习笔记
- A guide to keyword analysis
- A Guide to use SSL
- A working guide to kestrel
- A Guide To Reverse Tethering
- A Guide to Deep Learning
- 【IOS学习】Core Animation 学习笔记,以及demo
- Starters Guide to iOS Design
- hdu 1231
- SpringBoot Quickstart
- 模拟乘法运算之N的阶乘(大数阶乘)
- java中基础的Annotation--@Override @Deprecated @SuppressWarnings
- linux C 打印错误信息和标准输入输出
- A GUIDE TO IOS ANIMATION 2.0----学习笔记
- 游标变量
- Fatal error compiling: 无效的目标发行版: 1.8
- golang之cgo---调用C/C++动态库函数
- APP国际化&添加拨号权限&文字输入类型。
- android studio错误
- AJAX
- java与xml之SAX解析XML文档
- LeetCode--No.111--Minimum Depth of Binary Tree