我想显示网格线,就像相机打开时出现的那样.我正在使用AVCaptureManager.我应该使用核心图形来绘制网格线吗?这些网格线的大小是多少?
谢谢
解决方法
您确实可以在相机视图上添加自定义视图作为叠加层,以使用QuartzCore绘制网格.
这就是我在我的应用程序Subvision中做到的方式:
我用来绘制它的代码(注意:我的网格是可调整的,所以它可以是10×10,2×2等):
// ------------------------------------------------------------------------------- // Used for drawing the grids ontop of the view port // ------------------------------------------------------------------------------- - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context,0.5); CGContextSetStrokeColorWithColor(context,[UIColor whiteColor].CGColor); // --------------------------- // Drawing column lines // --------------------------- // calculate column width CGFloat columnWidth = self.frame.size.width / (self.numberOfColumns + 1.0); for(int i = 1; i <= self.numberOfColumns; i++) { CGPoint startPoint; CGPoint endPoint; startPoint.x = columnWidth * i; startPoint.y = 0.0f; endPoint.x = startPoint.x; endPoint.y = self.frame.size.height; CGContextMoveToPoint(context,startPoint.x,startPoint.y); CGContextAddLineToPoint(context,endPoint.x,endPoint.y); CGContextStrokePath(context); } // --------------------------- // Drawing row lines // --------------------------- // calclulate row height CGFloat rowHeight = self.frame.size.height / (self.numberOfRows + 1.0); for(int j = 1; j <= self.numberOfRows; j++) { CGPoint startPoint; CGPoint endPoint; startPoint.x = 0.0f; startPoint.y = rowHeight * j; endPoint.x = self.frame.size.width; endPoint.y = startPoint.y; CGContextMoveToPoint(context,endPoint.y); CGContextStrokePath(context); } }
在我的GridView类中,我定义了2个属性numberOfRows和numberOfColumns:
#import <UIKit/UIKit.h> @interface GridView : UIView @property (nonatomic,assign) int numberOfColumns; @property (nonatomic,assign) int numberOfRows; @end
这样做意味着我可以修改这两个值并具有无限可调的网格细分.