, 나는 UIButtons
을 제거하고 touchesBegan
, touchesMoved
및 touchesEnd
방법에 초점을 맞추었다. 특정 초기 위치와 특정 현재 위치에 UITouch
이 등록 된 경우에만 선을 그리는 CGContext
메서드를 통합했습니다. 이것이 내 문제에 대한 가장 이상적이고 효율적인 대답인지 확신 할 수는 없지만 잘 작동하고 내 프로젝트의 다음 단계로 넘어갈 수있었습니다. 누구든지이 솔루션을 개선하기위한 제안 사항이 있으면 크게 감사하겠습니다. 다음은이 솔루션에 사용한 코드 스 니펫입니다.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if([touch tapCount] == 2) {
image1_.image = nil;
return;
}
initialPoint = [touch locationInView:self.view];
//If initial touch to screen is within 15 pixels of Dot 1, set coordinates to Dot 1
if(initialPoint.x > 36 && initialPoint.x < 66 && initialPoint.y > 161 && initialPoint.y < 191)
{
initialPoint.x = 51.0;
initialPoint.y = 176.0;
}
//If initial touch to screen is within 15 pixels of Dot 2, set coordinates to Dot 2
if(initialPoint.x > 199.5 && initialPoint.x < 229.5 && initialPoint.y > 170.5 && initialPoint.y < 190.5)
{
initialPoint.x = 214.5;
initialPoint.y = 175.5;
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
currentPoint = [touch locationInView:self.view];
//If current touch to screen is within 15 pixels of Dot 2, and the initial touch is
//set to Dot 1, draw line
if(currentPoint.x > 199.5 && currentPoint.x < 229.5 && currentPoint.y > 170.5 && currentPoint.y < 190.5 && initialPoint.x == 51.0 && initialPoint.y == 176.0)
{
currentPoint.x = 214.5;
currentPoint.y = 175.5;
UIGraphicsBeginImageContext(self.view.frame.size);
[image1_.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width,
self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapSquare);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 4.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), initialPoint.x, initialPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
image1_.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lineIsDrawn = YES;
}
//If current touch to screen is within 15 pixels of Dot 3, and the initial touch is
//set to Dot 2, and a line has already been drawn between Dot 1 & Dot 2, draw line
if(currentPoint.x > 155.5 && currentPoint.x < 180.5 && currentPoint.y > 0 && currentPoint.y < 28.5 && initialPoint.x == 214.5 && initialPoint.y == 175.5 && lineIsDrawn == YES)
{
currentPoint.x = 170.5;
currentPoint.y = 13.5;
UIGraphicsBeginImageContext(self.view.frame.size);
[image1_.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width,
self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapSquare);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 4.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), initialPoint.x, initialPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
image1_.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
감사합니다. 우연히 그 응용 프로그램에 대해 언급 한 샘플입니다. 누구든지 UIButton 보낸 이벤트 설명에 대한 블로그/참조를 알고 있습니까? – des253