13.Quartz2D
来源:互联网 发布:有线路由器 知乎 编辑:程序博客网 时间:2024/06/05 02:28
- Quatz2D可以绘制控件
- 图形上下文CGContextRef保存绘图信息绘图状态决定绘制到哪里去
- - (void)drawRect:(CGRect)rect{ } view有多大rect就有多大
- 获取图形上下文
- 画线
- 画矩形
- 设置线条宽度
- 设置线条颜色
- 设置线条的头圆
- 画椭圆
- 画圆弧
- 闭合路径
- 画文字不需要上下文
- [word drawInRect:(cgrect) withAttributes:]
- 画图片不需要上下文
- 贝塞尔曲线
- 如果只是绘制线条必须使用stroke
- 让下一次使用在此是默认样式
- 矩阵旋转操作
- 裁剪当前图片
- drawRect: (CGRect)rect: 这个方法不能直接调用
- 为什么控件用weak 是因为weak可以不让计数器增加,利于提高性能
- 为什么用nonatomic是因为手机端重性能轻安全性
- 圆的增大方向是顺时针
CGContextRefctx = UIGraphicsGetCurrentContext();
2.1 确定起点
CGContextMoveToPoint(ctx, 10, 30);
2.2 添加一条线
CGContextAddLineToPoint(ctx, 50, 100);
2.3 渲染出图像
CGContextStrokePath(ctx);空心的图像
CGContextFillPath; 填充的图形
CGContextAddRect(ctx, CGRectMake(100, 100, 50 , 50));
CGContextSetLineWidth(ctx, 10);
5.1通过c语言来设置 CGContextSetRGBStrokeColor (ctx, r, g, b, a); 233.0/255.0f
Stroke只能配合stroke 如果用fill是没有效果的
CGContextSetRGBFillColor
5.2通过oc设置
[[UIColor redColor] setFill];
[[UIColor redColor] setStroke];
[[UIColor redColor] set] set是代表都有效果
6.1 CGContextSetLineCap(ctx, kCGLineCapRound);
6.2设置线之间链接线条的节点的样式
CGContextSetLineJoin(kCGLineJoinRound);
CGContextAddEllipseInRect(ctx, CGRectMake());
CGContextAddArc(ctx,圆心x,圆心y,半径,开始的角度,结束的角度,顺时针还是逆时针);
0顺时针 1逆时针
Fill只会填充起始和终点,并不会看点
CGContextClosePath(ctx);
10.1设置文字
NSString *word = @“我们饿了,要吃饭”;
10.2画文字
withAttribute用来表示文字的属性 字典!
[word drawAtPoint:(CGPoint)withAttributes:();
nsMutableDictionary *dict = [NSMutableDictionary dictionary]
Dict[NSForegroundColorAttributeName] = [UIColor redColor];
Dict[NSFontAttributeName] = [UIFont systemFontOfSize:14];
超出范围不显示自动换行
[word drawWithRect: options: attributes]
UIImage *image = [UIImage imageNamed:]
不会拉伸图片
[image drawAtPoint:CGPointMake(100, 100)];
会根据设定的范围拉伸图片
[image drawInRect:CGRectMake(10, 10, 100, 100)];
进行平铺展示
[image drawAsPatternInRect:rect]
13.1设置控制点
13.2设置起始点
13.3设置终点
CGContextAddQuadCurveToPoint(ctx,控制点X,控制点Y ,结束X,结束Y);
CGContextSaveGState(ctx);
开启一个上下文栈 copy的上下文放在栈中 保存的样式存在栈中
渲染图形的效果始终是根据上下文栈顶的上下文来确定
再画第二条线的时候恢复原来的上下文,放在上下文栈中
CGContextRestoreGState
矩阵操作要放在图形的上面
CGContextRotateCTM(ctx, M_PI_4); 旋转操作
上下文的操作缩放
CGContextScaleCTM(ctx, 0.5, 1);
上下文的平移
CGContextTranslateCTM(ctx, 100, 200);
绘制图形 之后裁剪图片
CGContextClip();
[self.arcView setNeedsDisplaty];
[self setNeedsDisplaty];
[self setNeedsDisplayInRect:];
- Storyboard和xib默认是归档在程序中,当使用的时候需要先解档。
- storyboard的本质是xib
- Nstimer通常是每隔一秒以上调用某一个方法的时候使用
- CADisplayLink 他可以调用一秒钟调用60次
- CADisplayLink *display = [CADsiplayLink displayLinkWithTarget:self selector:@selector(setNeedsDisplay)];
- UI层次只有一条线程 图片轮播器只有一条线程
- 上下文保存线条的属性和具体
- C语言在ocnil在c传NULL
- arc是编译器特性,是在对应的位置添加retainrelease,autoRelease。
- Analyze是上线的时候,我们需要进行内存检测。
- 两步合一步CGContextStrokeRect(ctx, CGRectMake(100, 100, 100, 50));
- UIButton *btn = [uibutton buttonwithtype];
- UIGraphicsBeginImageContextWithOptions(CGSize size, 不透明 == YES ,是否被压缩 0标示不压缩);
- NSArray/NSDictionary/NSString/NSData
- 图片要写入文件要转成2进制
- 类方法一般比对象方法快方法中没有访问成员变量的时候就可以使用类方法
- 抽取工具类方法 要找对应的类 可以写Extension或者Help
- 截屏
- 保存到相册中就不需要转成2进制
- UIImageWriteToSavedPhotosAlbum(clipImage, self, @selector(这个点进去有的))
- 三大事件触摸事件加速计事件 远程控制事件
- UIApplication UIVIEWcONTROLLER uivgIEW都继承自UIResponder都能处理事件
- touchesBegan touchesMoves touchesEnded touchesCancles
- motionBeganmotionEndedmotionCancelled
- 点击次数tabCount 触摸了多少秒timestamp
- Nsset存储无序的不同的对象
- 一次触摸事件获取的手指是一样的
- 获取当前触摸点的位置 CGPointcurrentPoint = [touch locationInView:self];
他就会调用 -(instancetype)initWithCoder:(NSCoder *)aDecoder{}
然后就会转换成代码
awakeFromNib这个事加载xib的时候调用先解档再调用这个
[Display addToRunLoop:[NSRunLoop mainRunLoop] forMode:]
CGMutablePathpath = CGPathCreateMutable();
CGPathMoveToPoint (path, NULL, 100, 100);
CGPathAddLineToPoint(path, NULL, 200, 300);
CGContextAddPath(ctx, path);
不过这是针对oc对象,智能管理oc对象的内存
如果是c语言需要手动管理内存
只要在c中出现create, copy, retain,都需要释放内存
CGPathRealease(path);corefundation也可以使用CFRelease;
CGFloat compressionQuality:标示图片质量,压缩值
NSData *imageData = [UIImageJPEGRepresentation(image, 压缩至)
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:@""可以拖文件夹 atomically:YES];
UIGraphicBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]
UIImage *clipImage = UIGraphicsGetImageFromCurrentImageContext();
UIgraphicsEndImageContext();
NSData *clipsImageData = UIImagePnGRepresentation(clipImage);
[clipImageData writeToFile:@"/User --- "automically: YES];
在这个方法中判断if(error)如果是真就保存失败
NSArry存储有序的可以重复的对象
NSDictionary:用键值对来存储数据
获取上一次的触摸点的位置[touch previousLocationInView:self];
- 13.Quartz2D
- quartz2d
- Quartz2d
- Quartz2D
- Quartz2D
- Quartz2D
- Quartz2D
- Quartz2D
- Quartz2D
- Quartz2D
- Quartz2D
- QuartZ2D
- Quartz2D
- Quartz2D
- Quartz2D
- Quartz2D
- Quartz2D绘图
- Quartz2D -(-)
- .NET 实验2-2
- 事件捕获和事件冒泡
- 三方库
- sql字符串拼接
- Android之NFC
- 13.Quartz2D
- React-开发工具
- org.apache.cxf.interceptor.Fault: The given SOAPAction ... does not match an operation
- 解析json字符串,并且获取其中某个key的值
- AAPT err(Facade for ): libpng error: Not a PNG file
- hdu3336(kmp+dp)
- 协方差的意义和计算公式
- struct option 的使用
- 用于操作基本类型数据的流对象