Objective c 只画好的直线
我有一个用Objective c 只画好的直线,objective-c,ios,image,drawing,Objective C,Ios,Image,Drawing,我有一个用UIScrollView和CATILDELAYER管理的大图像(如下图所示)。我在上面有一个绘图视图(UIView被绘图方法覆盖),以便绘制直线和矩形。 我试图找到一种方法,在放大图像时只重绘可见矩形,以提高性能 我找到了setNeedsDisplayInRect()方法,使用方法如下: CGRect visibleRect = CGRectApplyAffineTransform(scrollView.bounds, CGAffineTransformMakeScale(1.0 /
UIScrollView
和CATILDELAYER
管理的大图像(如下图所示)。我在上面有一个绘图视图(UIView
被绘图方法覆盖),以便绘制直线和矩形。
我试图找到一种方法,在放大图像时只重绘可见矩形,以提高性能
我找到了setNeedsDisplayInRect()
方法,使用方法如下:
CGRect visibleRect = CGRectApplyAffineTransform(scrollView.bounds, CGAffineTransformMakeScale(1.0 / imageScale, 1.0 / imageScale));
[self.drawingView setNeedsDisplayInRect:visibleRect];
但是现在,在我的
drawRect()
方法中,我重新绘制了所有的线条和矩形。我如何知道我必须重画哪些可见线?您需要这样的东西,具体取决于您如何绘制图像
- (void)drawRect:(CGRect)rect {
CATiledLayer *tiledLayer = (CATiledLayer *)[self layer];
CGSize _tileSize = tiledLayer.tileSize;
int firstCol = floorf(CGRectGetMinX(rect) / _tileSize.width);
int lastCol = floorf((CGRectGetMaxX(rect)-1) / _tileSize.width);
int firstRow = floorf(CGRectGetMinY(rect) / _tileSize.height);
int lastRow = floorf((CGRectGetMaxY(rect)-1) / _tileSize.height);
for (int row = firstRow; row <= lastRow; row++) {
for (int col = firstCol; col <= lastCol; col++) {
CGRect tileRect = CGRectMake(_tileSize.width * col, _tileSize.height * row, _tileSize.width, _tileSize.height);
tileRect = CGRectIntersection(self.bounds, tileRect);
// do your drawing
}
}
}
}
-(void)drawRect:(CGRect)rect{
CATiledLayer*平铺层=(CATiledLayer*)[自层];
CGSize _tileSize=tiledLayer.tileSize;
int firstCol=floorf(CGRectGetMinX(rect)/_tileSize.width);
int lastCol=floorf((CGRectGetMaxX(rect)-1)/_tileSize.width);
int firstRow=地板(CGRectGetMinY(rect)/_tileSize.高度);
int lastRow=地板((CGRectGetMaxY(rect)-1)/_tileSize.height);
对于(int row=firstRow;row您确定行的位置,然后使用nsbezierpath/cgpath
对其进行笔划,对吗
很可能,大部分时间将花在笔划算法上,而不是确定
。只需将path的clip region设置为drawRect的dirtyRect
参数。然后,虚拟笔划应该不会花费任何成本