現在のページに指で線を引くことができるアプリを作成しようとしています.描画ビューを使用しましたが、うまく機能しましたが、bufferlayer
現在のコンテキストに数回描画された後、深刻な遅延(遅い)問題があります. この問題を検索しましたが、呼び出されるCGLayer
たびに再描画されるようです。CGContextDrawLayerInRect(boardcontext,[self bounds],bufflayer)
そして、私のコードがあります。誰かが描画速度を改善するのを手伝ってくれるかどうかを確認してください。
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor=[UIColor clearColor];
self.points=[NSMutableArray array];
boardcontext=UIGraphicsGetCurrentContext();
layer=CGLayerCreateWithContext(boardcontext, self.frame.size, NULL);
}
return self;
}
-(void)drawLayer{
CGContextRef context=CGLayerGetContext(layer);
for (int i=points.count-2; i<points.count-1; i++) {
CGPoint pt1=[[self.points objectAtIndex:i]CGPointValue];
CGPoint pt2=[[self.points objectAtIndex:i+1]CGPointValue];
CGContextMoveToPoint(context, pt1.x, pt1.y);
CGContextAddLineToPoint(context, pt2.x, pt2.y);
}
CGContextStrokePath(context);
}
- (void)drawRect:(CGRect)rect
{
// Drawing code
boardcontext=UIGraphicsGetCurrentContext();
CGContextDrawLayerInRect(boardcontext, rect, layer);
// CGContextDrawLayerAtPoint(boardcontext,CGPointZero,layer);
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[points removeAllObjects];
CGPoint pt = [[touches anyObject]locationInView:self];
[self.points addObject:[NSValue valueWithCGPoint:pt]];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint pt = [[touches anyObject]locationInView:self];
[self.points addObject:[NSValue valueWithCGPoint:pt]];
[self drawLayer];
[self setNeedsDisplay];
}
また、外部CGbitmapcontext
を呼び出すのではなく、バッファーになる a を作成しようとしましたが、それは use よりもはるかに悪いようでした。UIGraphicsGetCurrentContext()
drawRect()
UIGraphicsGetCurrentContext()