嘿客觀的C IM初學者請幫我如何在觸摸事件上畫線?
我把下面的代碼,但不能正常工作.....
-(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);
}
}
我在viewDidLoad方法聲明CONTEX也嘗試聯繫事件申報但不工作...
我的應用程序日誌文件的樣子......
X:0 Y:1079934976在觸摸移動週四1月13日11點20分05秒。當地 的DragDrop [536 ]:
CGContextAddLineToPoint:無效的上下文爲0x0 2011-01-13 11:20:05.149 的DragDrop [536:207]×:0 Y:1079902208週四年01月13 11點20分05秒。本地 的DragDrop [536]:
CGContextSetRGBStrokeColor:無效的上下文爲0x0週四年01月13 11點20分05秒 。本地的DragDrop [536]:
CGContextDrawPath:無效的上下文爲0x0週四年01月13 11點20分05秒。本地 的DragDrop [536]:
CGContextMoveToPoint:invalid context 0x0 2011-01-13 11:20:0 5.199 的DragDrop [536:207]×:0 Y:1079934976在觸摸移動星期四年01月13 11點20分05秒 。本地的DragDrop [536]:
CGContextAddLineToPoint:無效的上下文爲0x0 2011-01-13 11:20 :05.200 的DragDrop [536:207]×:0 Y:1079885824