誰かの助けが必要です。ユーザーの指の動きに合わせて、1行ずつ表示できるPNGファイルで線を描きたい(スペースあり)。下の画像は、私が本当にやりたいことを示しています。
これが私のコードです…</p>
-(CGPoint)generateDrawingPt:(NSMutableArray*)pointsArray{
CGFloat brushDia = 20.0f;
int spacing;
int distance;
CGPoint drawnPoint;
CGPoint tempPoint;
CGPoint resetPoint;
for (int i=0; i<pointsArray.count-1; i++) {
NSValue *curPointValue = [pointsArray objectAtIndex:i];
CGPoint curPoint = curPointValue.CGPointValue;
NSValue *nextPointValue = [pointsArray objectAtIndex:i+1];
CGPoint nextPoint = nextPointValue.CGPointValue;
distance=(CGFloat)sqrtf((curPoint.x-nextPoint.x)*(curPoint.x-nextPoint.x)+(curPoint.y-nextPoint.y)*(curPoint.y-nextPoint.y));
CGFloat dX = (nextPoint.x-curPoint.x);
CGFloat dY = (nextPoint.y-curPoint.y);
if (dX==0||dY==0 ||distance<0.5*brushDia){
resetPoint=CGPointMake((nextPoint.x+brushDia), (nextPoint.y+brushDia));
tempPoint=resetPoint;
resetPoint=drawnPoint;
drawnPoint=tempPoint;
curPoint.x=drawnPoint.x;
curPoint.y=drawnPoint.y;
} else {
drawnPoint=CGPointMake((curPoint.x-brushDia/2), (curPoint.y-brushDia/2));
curPoint.x=drawnPoint.x;
curPoint.y=drawnPoint.y;
}
}
return drawnPoint;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
mouseSwiped =YES;
CGPoint drawingPt;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
NSValue *locationValue = [NSValue valueWithCGPoint:currentPoint];
[MovingPathPoints addObject:locationValue];
drawingPt =[self generateDrawingPt:MovingPathPoints];
UIGraphicsBeginImageContext(self.mainImage.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.mainImage.image drawInRect:CGRectMake(0, 0, self.mainImage.frame.size.width, self.mainImage.frame.size.height)];
UIImage * brushImagetexture = [UIImage imageNamed:@"brushImg.png"];
[brushImagetexture drawAtPoint:drawingPt blendMode:kCGBlendModeHardLight alpha:0.6f];
CGContextStrokePath(context);
self.mainImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
previousPoint = currentPoint;
}
上記のコードでは、本当に悪い結果が得られました。問題には次のものがあります
-いくつかの PNG 画像は、私の指の経路をたどりません。・また、反応が遅い。PNG 画像は、指の端が移動した後に描画されます。
誰か助けてくれませんか?
少し早いですがお礼を。