- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touch began");
UITouch *touch = [touches anyObject];
// 3번 터치하면 이미지 초기화
if ([touch tapCount] == 3) {
drawImage.image = nil;
return;
}
lastPoint = [touch locationInView:self.drawImageView];
}
// Override메서드
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touch move");
UITouch *touch = [touches anyObject];
currentPoint = [touch locationInView:self.drawImageView];
UIGraphicsBeginImageContext(self.drawImageView.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.drawImageView.frame.size.width, self.drawImageView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.1, 0.1, 0.1, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
}
'프로그래밍 > iOS' 카테고리의 다른 글
UIImage에서 그림 그리는 방법 (0) | 2012.01.12 |
---|---|
간단한 손가락으로 그리기 소스 (0) | 2012.01.12 |
터치가 발생했을때 뷰 위에 직접 그림을 그리기 위한 코드 (0) | 2012.01.12 |
UILabel 세로 정렬하기 ( Vertical align ) (0) | 2012.01.12 |
UIImageView 테두리넣기 및 모서리 깎기 (0) | 2012.01.11 |