我是新開發的iOS。創建可伸縮路徑CGContextPath
我用Core Graphics/UIKit繪製時出現問題。 我想在Window中實現一個像paint形狀的函數。
我使用此源:https://github.com/JagCesar/Simple-Paint-App-iOS,並添加新的功能。
當touchesMoved時,我繪製一個形狀,基於touchesBegan的點和當前的觸摸點。它繪製所有的形狀。
- (void)drawInRectModeAtPoint:(CGPoint)currentPoint
{
UIGraphicsBeginImageContext(self.imageViewDrawing.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.currentColor setFill];
[self.imageViewDrawing.image drawInRect:CGRectMake(0, 0, self.imageViewDrawing.frame.size.width, self.imageViewDrawing.frame.size.height)];
CGContextMoveToPoint(context, self.beginPoint.x, self.beginPoint.y);
CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);
CGContextAddLineToPoint(context, self.beginPoint.x * 2 - currentPoint.x, currentPoint.y);
CGContextAddLineToPoint(context, self.beginPoint.x, self.beginPoint.y);
CGContextFillPath(context);
self.currentImage = UIGraphicsGetImageFromCurrentImageContext();
self.imageViewDrawing.image = self.currentImage;
UIGraphicsEndImageContext();
}
我的意思是,我只希望創建一個形狀,當的touchesBegan,應用程序記錄點,當touchesMoved,形狀由觸摸縮放,當touchesEnd,繪製形狀的ImageContex
希望你能給我一些提示來做到這一點。 謝謝。
因此,你的意思是你想從觸摸開始拖出到結束,每次獲取更新時調整圖像大小,然後將最終圖像保存到上下文中? – Wain
我的意思是,我想創建只有一個形狀, 當touchesBegan,應用程序記錄點, 當touchesMoved,形狀是通過觸摸縮放, ,當touchesEnd,繪製形狀到ImageContext – user2818764