2013-04-25 1 views
1

나는 터치 이벤트를 사용하여 서명을 그렸습니다. 나는 잘 작동하지만 그것은 문제가 그것이 올바른 줄을 그릴하지 않는 것입니다 포럼에서 코드를 가지고 우리가 그릴로 라인을 그려 라인에 알리 축소 여기 내 그림의 화면 내 코드 여기터치 이벤트를 사용하여 아이폰 애플 리케이션에서 라인을 그리기

입니다

enter image description here

- (void)viewDidLoad { 
    [super viewDidLoad]; 
drawImage = [[UIImageView alloc] initWithImage:nil]; 
drawImage.frame = self.view.frame; 
[self.view addSubview:drawImage]; 
self.view.backgroundColor = [UIColor lightGrayColor]; 
mouseMoved = 0; 
    } 

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

mouseSwiped = NO; 
UITouch *touch = [touches anyObject]; 

if ([touch tapCount] == 2) { 
    drawImage.image = nil; 
    return; 
} 

lastPoint = [touch locationInView:self.view]; 
lastPoint.y -= 20; 

    } 


    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 

    mouseSwiped = YES; 

UITouch *touch = [touches anyObject]; 
CGPoint currentPoint = [touch locationInView:self.view]; 
currentPoint.y -= 20; 


UIGraphicsBeginImageContext(self.view.frame.size); 
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); 
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); 
CGContextBeginPath(UIGraphicsGetCurrentContext()); 
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); 
CGContextStrokePath(UIGraphicsGetCurrentContext()); 
drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

lastPoint = currentPoint; 

mouseMoved++; 

if (mouseMoved == 10) { 
    mouseMoved = 0; 
} 

    } 

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch *touch = [touches anyObject]; 

    if ([touch tapCount] == 2) { 
    drawImage.image = nil; 
    return; 
    } 


    if(!mouseSwiped) { 
    UIGraphicsBeginImageContext(self.view.frame.size); 
    [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); 
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); 
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
    CGContextStrokePath(UIGraphicsGetCurrentContext()); 
    CGContextFlush(UIGraphicsGetCurrentContext()); 
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
     } 
      } 
+1

귀하의 문제와 의문점을 다시 말해 주시겠습니까? – alecail

답변

0

당신은 화살표가 스크린과 당신에 추가입니다 버튼의 누름 버튼을 추가 할 수 있습니다 터치를 사용하여 회전하고 크기를 조정할 수 있습니다.

+0

나는 정상적인 사람이이 코드를 사용하여 이렇게 할 수있는 서명을하고 싶습니다. –

관련 문제