Iphone 用于手指触摸绘图的UIBezierPath平滑曲线
我想在手指触摸画线上平滑曲线,我只想在UIBezierPath中解决我的代码不能完全平滑线Iphone 用于手指触摸绘图的UIBezierPath平滑曲线,iphone,objective-c,ios,xcode,ipad,Iphone,Objective C,Ios,Xcode,Ipad,我想在手指触摸画线上平滑曲线,我只想在UIBezierPath中解决我的代码不能完全平滑线 @implementation MyLineDrawingView @synthesize undoSteps; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code [super setBack
@implementation MyLineDrawingView
@synthesize undoSteps;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[super setBackgroundColor:[UIColor whiteColor]];
pathArray=[[NSMutableArray alloc]init];
bufferArray=[[NSMutableArray alloc]init];
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
[[UIColor blackColor] setStroke];
for (UIBezierPath *_path in pathArray)
[_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
}
#pragma mark - Touch Methods
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[bufferArray removeAllObjects];
myPath=[[UIBezierPath alloc]init];
myPath.lineWidth=5;
myPath.miterLimit=-10;
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];
}
-(void)undoButtonClicked
{
if([pathArray count]>0)
{
UIBezierPath *_path=[pathArray lastObject];
[bufferArray addObject:_path];
[pathArray removeLastObject];
[self setNeedsDisplay];
}
}
-(void)redoButtonClicked
{
if([bufferArray count]>0){
UIBezierPath *_path=[bufferArray lastObject];
[pathArray addObject:_path];
[bufferArray removeLastObject];
[self setNeedsDisplay];
}
}
- (void)dealloc
{
[pathArray release];
[bufferArray release];
[super dealloc];
}
@end
我使用我的代码获得输出,如下面的屏幕截图:
我想要平滑曲线输出,如下面的屏幕截图:
能有人帮我吗?非常感谢
提前谢谢 问题在于,您仅使用
addLineToPoint:
向路径添加点。这相当于创建一系列直线。您确实需要添加控制点,例如在Illustrator或Sketch中绘制曲线路径时可能拖动的控制柄
您可以使用addCurveToPoint:controlPoint1:controlPoint2:
添加这些;诀窍是找出控制点的位置,相对于您实际从触摸*
事件中获得的点
为了更好地讨论可能的技术,我推荐以下问题: