사용자가 iPad/iPhone 화면에서 손가락을 움직일 때 점선이 그려지는보기가 있습니다. LastLocation으로 저장된 점과 CurrentLocation 인 점 사이에 선을 그립니다. 도면은 화면 상에 지속되어야한다. 이 문제는 touchMoved 이벤트가 발생할 때마다 발생하며 그림 응용 프로그램과 마찬가지로 손가락을 드래그 한 위치에서 점선을 그릴 수있게됩니다.더 나은 성능을 가진 UIImageView에서 페인팅
나는 touch 이벤트가 발생하면 다음과 같은 함수를 호출한다. 뷰에는 drawImage라는 UIImageView가 포함되어 있습니다. UIImageView를 그려진 선을 지속하는 수단으로 사용합니다. 이것은 사람들이 일반적으로 응용 프로그램을 그리는 방법과는 달리 매우 느립니다. CGContextRef 호출을 사용하여 지속적인 그림을 만드는 더 좋은 방법에 대한 통찰력은 인정 될 것입니다.
/* Enter bitmap graphics drawing context */
UIGraphicsBeginImageContext(frame.size);
/* Draw the previous frame back in to the bitmap graphics context */
[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)];
/* Draw the new line */
CGContextRef ctx = UIGraphicsGetCurrentContext();
/* Set line draw color to green, rounded cap end and width of 5 */
CGContextSetLineDash(ctx, 0, dashPattern, 2);
CGContextSetStrokeColorWithColor(ctx, color);
CGContextSetLineCap(ctx, kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound
CGContextSetLineWidth(ctx, 5.0); // for size
/* Start the new path point */
CGContextMoveToPoint(ctx, LastLocation.x, LastLocation.y);
CGContextAddLineToPoint(ctx, Current.x, Current.y);
CGContextStrokePath(ctx);
/* Push the updated graphics back to the image */
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
'drawImage.image drawInRect'호출이 매우 느리고 본질적으로 전체 이미지를 다시 그립니다.
더 빠른 방법이 있나요? 그림 그리기를 위해 블로그의 몇 군데에서 이와 같은 코드를 그리는 것을 보았습니다.하지만 약간 느립니다. 주제에 대한 의견을 듣고 싶습니다.
Fuzz,이 작업을 수행 했습니까? 나는 매우 비슷한 문제를 찾아 내려고 노력하고있다. 당신이 생각한 것을 듣고 싶습니다. 고마워요 - fxshot –