{"id":422,"date":"2014-12-01T11:34:49","date_gmt":"2014-12-01T03:34:49","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=422"},"modified":"2016-07-14T22:48:48","modified_gmt":"2016-07-14T14:48:48","slug":"quartz2d%e7%9a%84%e5%9f%ba%e6%9c%ac%e4%bd%bf%e7%94%a8%ef%bc%88%e7%ac%ac%e4%ba%8c%e8%ae%b2%ef%bc%9a%e5%9f%ba%e6%9c%ac%e5%9b%be%e5%bd%a2%e7%bb%98%e5%88%b6%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2014\/12\/01\/113449422.html","title":{"rendered":"Quartz2D\u7684\u57fa\u672c\u4f7f\u7528\uff08\u7b2c\u4e8c\u8bb2\uff1a\u57fa\u672c\u56fe\u5f62\u7ed8\u5236\uff09"},"content":{"rendered":"<p><strong>\u4e00\u3001\u57fa\u672c\u7ed8\u56fe\u65b9\u6cd5<\/strong><\/p>\n<p>1\u3001\u79fb\u52a8\u753b\u7b14\u4f4d\u7f6e\u65b9\u6cd5\u5f62\u5f0f\u5982  CGContextMovexxxx\uff0c \u5982\uff1aCGContextMoveToPoint(CGContextRef c, CGFloat x, CGFloat y)\u4e3a\u79fb\u52a8\u5230\u5750\u6807\uff08x\uff0c y\uff09<\/p>\n<p>2\u3001\u63cf\u8ff0\u56fe\u5f62\u65b9\u6cd5\u5982 CGContextAddxxxx\uff0c\u5982\uff1a<br \/>\nCGContextAddLineToPoint(CGContextRef c, CGFloat x, CGFloat y)\uff0c\u63cf\u8ff0\u4e00\u4e2a\u7ebf\u6bb5\u4ece\u5f53\u524d\u753b\u7b14\u70b9\u5230\u70b9\uff08x\uff0cy\uff09<br \/>\nGContextAddRect(CGContextRef c, CGRect rect)\uff0c\u6839\u636e\u4f20\u5165\u7684rect\u63cf\u8ff0\u4e00\u4e2a\u77e9\u5f62\uff0crect\u4e2d\u6307\u5b9a\u4e86\u4f4d\u7f6e\u4e0e\u5c3a\u5bf8<br \/>\nCGContextAddEllipseInRect(CGContextRef context, CGRect rect)\uff0c\u6839\u636e\u4f20\u5165\u7684rect\u63cf\u8ff0\u4e00\u4e2a\u5728rect\u4e2d\u80fd\u5bb9\u7eb3\u7684\u6700\u5927\u692d\u5706\uff0c\u5982\u679c\u4e3arect\u4e2dwidth\u4e0eheight\u76f8\u7b49\u5219\u4e3a\u5706<br \/>\nCGContextAddArc(CGContextRef c, CGFloat x, CGFloat y, CGFloat radius, CGFloat startAngle, CGFloat endAngle, int clockwise)\uff0c\u8be5\u51fd\u6570\u4e3a\u753b\u4e00\u6bb5\u5706\u5f27\uff0c\u4f20\u5165\u7684\u53c2\u6570\u5206\u522b\u4e3a\uff1a\u4e0a\u4e0b\u6587\uff0c\u5706\u5fc3x\u5750\u6807\uff0c\u5706\u5fc3y\u5750\u6807\uff0c \u534a\u5f84\uff0c \u5f00\u59cb\u5f27\u5ea6\u503c\uff0c\u7ed3\u675f\u5f27\u5ea6\u503c\uff0c\u987a\u65f6\u949f\uff081\u4e3a\u987a\u65f6\u949f\uff0c0\u4e3a\u9006\u65f6\u949f\uff09<\/p>\n<p>3\u3001\u56fe\u5f62\u8bbe\u7f6e\u65b9\u6cd5\u5982 CGContextSetxxxx\uff0c\u5982\uff1a<br \/>\nCGContextSetRGBFillColor(CGContextRef context, CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha)\uff0c\u586b\u5145\u56fe\u5f62\u65f6\u4f7f\u7528\u7684\u989c\u8272RGB\u4e0e\u900f\u660e\u5ea6\u503c<\/p>\n<p>4\u3001\u56fe\u5f62\u6e32\u67d3 CGContextxxxxPath()\uff0c\u5982\uff1a<br \/>\nCGContextFillPath(CGContextRef c)\uff0c \u6e32\u67d3\u4e3a\u5b9e\u5fc3\u56fe\u5f62<br \/>\nCGContextStrokePath(CGContextRef c)\uff0c \u6e32\u67d3\u4e3a\u7a7a\u5fc3\u56fe\u5f62<!--more--><br \/>\n<strong>\u4e8c\u3001\u793a\u4f8b\u4ee3\u7801<\/strong><\/p>\n<pre lang=\"objc\" line=\"1\">\/\/\n\/\/  SAView.m\n\/\/  Quartz2D\n\/\/\n\/\/  Created by \u4f59\u897f\u5b89 on 14\/12\/1.\n\/\/  Copyright (c) 2014\u5e74 Sian. All rights reserved.\n\/\/\n\n#import \"SAView.h\"\n\n@implementation SAView\n\n-(void)drawRect:(CGRect)rect\n{\n    \/\/ 1\u3001\u83b7\u53d6\u4e0a\u4e0b\u6587(\u5f00\u542f\u5f53\u524d\u7ed8\u56fe\u677f)\n    CGContextRef ctx = UIGraphicsGetCurrentContext();\n    \n    \/\/ 2\u3001\u7ed8\u5236\u56fe\u5f62\n    \/\/ 2.1 \u753b\u77e9\u5f62\n    \/\/ \u7ed8\u5236\u77e9\u5f62\uff0c\u8f93\u5165\u4e0a\u4e0b\u6587\u53ca\u77e9\u5f62\u7684\u5927\u5c0f\u5c3a\u5bf8Rect\n    \/\/ CGContextAddRect(CGContextRef c, CGRect rect)\n    CGContextAddRect(ctx, (CGRect){50, 50, 100, 100});\n    \/\/ \u6e32\u67d3\u7a7a\u5fc3\u56fe\u5f62\u5230\u5f53\u524dView\n    CGContextStrokePath(ctx);\n    \n    \/\/ 2.2 \u753b\u5706\uff08\u692d\u5706\uff09\n    \/\/ \u7ed8\u5236\u692d\u5706\uff08\u5706\u662f\u692d\u5706\u7684\u4e00\u79cd\uff09\uff0c\u540c\u6837\u6307\u5b9a\u4e0a\u4e0b\u6587\u4e0e\u5706\u6240\u5360\u636e\u7684Rect\u5373\u53ef\n    \/\/ CGContextAddEllipseInRect(CGContextRef context, CGRect rect)\n    CGContextAddEllipseInRect(ctx, (CGRect){100, 200, 100, 100});\n    \/\/ \u6e32\u67d3\u5b9e\u5fc3\u56fe\u5f62\u5230\u5f53\u524dView\n    CGContextFillPath(ctx);\n    \n    \/\/ 2.3 \u753b\u5706\u5f27\uff08\u5706\uff09\n    \/\/ \u5c06\u201c\u753b\u7b14\u201d\u79fb\u52a8\u5230\u753b\u5f27\u7684\u8d77\u70b9\uff0c\u5982\u679c\u6ca1\u6709\u8fd9\u53e5\u4f1a\u4ece\u4e0a\u6b21\u7ed8\u56fe\u7684\u7ec8\u70b9\u201c\u62d6\u7ebf\u201d\u5230\u5f53\u524d\u7ed8\u56fe\u8d77\u70b9\n    CGContextMoveToPoint(ctx, 200, 400);\n    \/\/ \u7ed8\u5236\u5706\u5f27\uff0c\u6307\u5b9a\u5706\u5f27\u7684\u5706\u5fc3\u3001\u534a\u5f84\u3001\u5f27\u5ea6\u8d77\u70b9\u4e0e\u7ec8\u70b9\uff0c\u7ed8\u5236\u65b9\u5411(\u987a\u65f6\u949f\u6216\u9006\u65f6\u949f)\n    \/\/ CGContextAddArc(CGContextRef c, CGFloat x, CGFloat y, CGFloat radius, CGFloat startAngle, CGFloat endAngle, int clockwise)\n    CGContextAddArc(ctx, 150, 400, 50, 0, M_PI * 2, 0);\n    \/\/ \u8bbe\u7f6e\u586b\u5145\u989c\u8272RGB\u503c\n    \/\/ CGContextSetRGBFillColor(CGContextRef context, CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha)\n    CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);\n    \/\/ \u6e32\u67d3\u5b9e\u5fc3\u56fe\u5f62\u5230\u5f53\u524dView\n    CGContextFillPath(ctx);\n}\n\n@end<\/pre>\n<p><strong>\u4e09\u3001\u8fd0\u884c\u6548\u679c<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2016\/07\/iOS-\u6a21\u62df\u5668\u5c4f\u5e55\u5feb\u7167\u201c2014\u5e7412\u67081\u65e5-\u4e0a\u534811.33.59\u201d.png\" alt=\"iOS \u6a21\u62df\u5668\u5c4f\u5e55\u5feb\u7167\u201c2014\u5e7412\u67081\u65e5 \u4e0a\u534811.33.59\u201d\" width=\"320\" height=\"480\" class=\"alignnone size-full wp-image-423\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u57fa\u672c\u7ed8\u56fe\u65b9\u6cd5 1\u3001\u79fb\u52a8\u753b\u7b14\u4f4d\u7f6e\u65b9\u6cd5\u5f62\u5f0f\u5982 CGContextMovexxxx\uff0c \u5982\uff1aCGContextMoveToPoint(CGContextRef c, CGFloat x, CGFloat y)\u4e3a\u79fb\u52a8\u5230\u5750\u6807\uff08x\uff0c y\uff09 2\u3001\u63cf\u8ff0\u56fe\u5f62\u65b9\u6cd5\u5982 CGContextAddxxxx\uff0c\u5982\uff1a CGContextAddLineToPoint(CGContextRef c, CGFloat x, CGFloat y)\uff0c\u63cf\u8ff0\u4e00\u4e2a\u7ebf\u6bb5\u4ece\u5f53\u524d\u753b\u7b14\u70b9\u5230\u70b9\uff08x\uff0cy\uff09 GContextAddRect(CGContextRef c, CGRect rect)\uff0c\u6839\u636e\u4f20\u5165\u7684rect\u63cf\u8ff0\u4e00\u4e2a\u77e9\u5f62\uff0crect\u4e2d\u6307\u5b9a\u4e86\u4f4d\u7f6e\u4e0e\u5c3a\u5bf8 CGContextAddEllipseInRect(CGContextRef context, CGRect rect)\uff0c\u6839\u636e\u4f20\u5165\u7684rect\u63cf\u8ff0\u4e00\u4e2a\u5728rect\u4e2d\u80fd\u5bb9\u7eb3\u7684\u6700\u5927\u692d\u5706\uff0c\u5982\u679c\u4e3arect\u4e2dwidth\u4e0eheight\u76f8\u7b49\u5219\u4e3a\u5706 CGContextAddArc(CGContextRef c, CGFloat x, CGFloat y, CGFloat radius, CGFloat startAngle, CGFloat endAngle, int clockwise)\uff0c\u8be5\u51fd\u6570\u4e3a\u753b\u4e00\u6bb5\u5706\u5f27\uff0c\u4f20\u5165\u7684\u53c2\u6570\u5206\u522b\u4e3a\uff1a\u4e0a\u4e0b\u6587\uff0c\u5706\u5fc3x\u5750\u6807\uff0c\u5706\u5fc3y\u5750\u6807\uff0c \u534a\u5f84\uff0c \u5f00\u59cb\u5f27\u5ea6\u503c\uff0c\u7ed3\u675f\u5f27\u5ea6\u503c\uff0c\u987a\u65f6\u949f\uff081\u4e3a\u987a\u65f6\u949f\uff0c0\u4e3a\u9006\u65f6\u949f\uff09 3\u3001\u56fe\u5f62\u8bbe\u7f6e\u65b9\u6cd5\u5982 CGContextSetxxxx\uff0c\u5982\uff1a CGContextSetRGBFillColor(CGContextRef context, CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha)\uff0c\u586b\u5145\u56fe\u5f62\u65f6\u4f7f\u7528\u7684\u989c\u8272RGB\u4e0e\u900f\u660e\u5ea6\u503c 4\u3001\u56fe\u5f62\u6e32\u67d3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[16],"class_list":["post-422","post","type-post","status-publish","format-standard","hentry","category-project","tag-quartz2d"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=422"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/422\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}