이것은 iPhone touch 위임이 작동하는 방식입니다. 전화 번호는 touchesBegan:
, touchesMoved:
및 touchesEnded:
입니다.
CGContextRef context = UIGraphicsGetCurrentContext();
[current set];
CGContextSetLineWidth(context, 4.0f);
for (int i = 0; i < (self.points.count - 1); i++)
{
CGPoint pt1 = POINT(i);
CGPoint pt2 = POINT(i+1);
CGContextMoveToPoint(context, pt1.x, pt1.y);
CGContextAddLineToPoint(context, pt2.x, pt2.y);
CGContextStrokePath(context);
}
그리고이 코드의 도움으로
, 당신은 그것을 만들 준비가되어 있어야합니다 : 선을 그리려면이 코드가 필요합니다. 도움이 필요한 경우 여기에 의견을 남기거나 다른 질문을하십시오.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touch_point = [touch locationInView:self.view];
NSLog(@"x: %.0f y: %.0f", touch_point.x, touch_point.y);
}
가 drawRect
당신이보기를 추가 있고, 선을 그리고 선을 그리려면 :
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 1.0);
CGContextSetStrokeColorWithColor(context, [UIColor orangeColor].CGColor);
// ...
CGContextMoveToPoint(context, one_x, one_y);
CGContextAddLineToPoint(context, two_x, two_y);
CGContextStrokePath(context);
// ...
}
CGPoint pt = [[touches anyObject] locationInView:self];
[self.points addObject:[NSValue valueWithCGPoint:pt]];
[self setNeedsDisplay];
: s/Iphone/iPhone. 또한, 질문의 제목 앞에 "(iphone)"을 붙일 필요가 없습니다. 그것이 바로 태그입니다. 정말. –