Note that there are some explanatory texts on larger screens.

plurals
  1. POHow To Draw line on touch event?
    text
    copied!<p>Hey i m beginner of objective C Please Help me </p> <p>i make following code but not work.....</p> <pre><code>-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; if ([touch view] == self.view) { CGPoint location = [touch locationInView:self.view]; loc1 = location; CGContextMoveToPoint(context, location.x, location.y); NSLog(@"x:%d y:%d At Touch Begain", loc1.x, loc1.y); } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; if ([touch view] == self.view) { CGPoint location = [touch locationInView:self.view]; CGContextMoveToPoint(context, loc1.x, loc1.y); NSLog(@"x:%d y:%d At Touch Move", loc1.x, loc1.y); CGContextAddLineToPoint(context, location.x, location.y); NSLog(@"x:%d y:%d", location.x, location.y); } } </code></pre> <p>i declare contex in viewdidload method and also try to declare in touch event but not work...</p> <p>My app Log file look like...</p> <blockquote> <p>x:0 y:1079934976 At Touch Move Thu Jan 13 11:20:05 .local DragDrop[536] : </p> <p>CGContextAddLineToPoint: invalid context 0x0 2011-01-13 11:20:05.149 DragDrop[536:207] x:0 y:1079902208 Thu Jan 13 11:20:05 .local DragDrop[536] :</p> <p>CGContextSetRGBStrokeColor: invalid context 0x0 Thu Jan 13 11:20:05 .local DragDrop[536] :</p> <p>CGContextDrawPath: invalid context 0x0 Thu Jan 13 11:20:05 .local DragDrop[536] : </p> <p>CGContextMoveToPoint: invalid context 0x0 2011-01-13 11:20:05.199 DragDrop[536:207] x:0 y:1079934976 At Touch Move Thu Jan 13 11:20:05 .local DragDrop[536] : </p> <p>CGContextAddLineToPoint: invalid context 0x0 2011-01-13 11:20:05.200 DragDrop[536:207] x:0 y:1079885824</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload