我正在使用 UIBezierPath 进行绘图,并且我已经编写了关于触摸事件的代码并且其工作正常,但是我的曲线不平滑,当我移动手指并绘制一些曲线时,它们不平滑。
- (void)drawRect:(CGRect)rect
{
[[UIColor redColor] setStroke];
for (UIBezierPath *_path in pathArray)
[_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
}
#pragma mark - Touch Methods
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
myPath=[[UIBezierPath alloc]init];
myPath.lineWidth=5;
myPath.lineCapStyle = kCGLineCapRound;
myPath.flatness = 0.0;
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath moveToPoint:[mytouch locationInView:self]];
[pathArray addObject:myPath];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath addLineToPoint:[mytouch locationInView:self]];
[self setNeedsDisplay];
}
这是图像
在上图中,如果您看到字母 a 和 d,您会发现曲线不平滑。我应该怎么做才能获得平滑的曲线?
那么你正在使用addLinePoint
显然你得到的是直线,而不是曲线。您可能会对其他为您提供平滑曲线的方法感兴趣:添加曲线到点 http://developer.apple.com/library/ios/documentation/uikit/reference/UIBezierPath_class/Reference/Reference.html#//apple_ref/occ/instm/UIBezierPath/addCurveToPoint:controlPoint1:controlPoint2: or 添加四线到点 http://developer.apple.com/library/ios/documentation/uikit/reference/UIBezierPath_class/Reference/Reference.html#//apple_ref/occ/instm/UIBezierPath/addQuadCurveToPoint:controlPoint:。但正如您从 API 中看到的,除了您实际用手指绘制的点之外,您还需要控制点,这些控制点不是随绘图而来的。甚至 Photoshop 也会要求您在进行曲率处理时移动它们。换句话说,让你的手绘“自动”流畅涉及相当多的数学知识。谷歌“平滑手绘”,你至少会得到这些点
平滑手绘的自由形状 https://stackoverflow.com/questions/6363568/smoothing-a-hand-drawn-free-shape
平滑手绘曲线 https://stackoverflow.com/questions/5525665/smoothing-a-hand-drawn-curve
它实际上根本不是 iOS 特定的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)