-1

ユーザーが指で線を引くことができるアプリケーションを書いています。

これはコードです:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ 
    NSLog(@"BEGAN");//TEST OK
    UITouch* tap=[touches anyObject]; 
    start_point=[tap locationInView:self];
}


-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    NSLog(@"MOVED");//TEST OK
    UITouch* tap=[touches anyObject]; 
    current_point=[tap locationInView:self];
    [self DrawLine:start_point end:current_point];
    start_point=current_point;
} 


-(void)DrawLine: (CGPoint)start end:(CGPoint)end 
{
    context= UIGraphicsGetCurrentContext();
    CGColorSpaceRef space_color= CGColorSpaceCreateDeviceRGB(); 
    CGFloat component[]={1.0,0.0,0.0,1};
    CGColorRef color = CGColorCreate(space_color, component);

    //draw line 
    CGContextSetLineWidth(context, 1);
    CGContextSetStrokeColorWithColor(context, color);
    CGContextMoveToPoint(context, start.x, start.y);
    CGContextAddLineToPoint(context,end.x, end.y);
    CGContextStrokePath(context);
}

私の問題は、画面に線を引いても線が表示されないことです。

PS I draw on main View of application

4

2 に答える 2

3
context= UIGraphicsGetCurrentContext();

UIGraphicsGetCurrentContext()メソッドの外から呼び出していますdrawRect:。したがって、返されnilます。nilしたがって、次の関数は、実際には明らかに機能しないコンテキストを描画しようとします

于 2013-09-28T16:34:33.640 に答える