我想用我的手指畫出一條直線,並根據我離原點的距離自動調整大小。拉伸UIBezierPath線?
因此,如果我在中間觸摸屏幕並將手指滑出,則會出現「伸展」線條,並隨着手指在屏幕上移動而圍繞orgin點旋轉。當我擡起我的手指。目標點應完成並創建一條線。我可以將手指拖過屏幕並在屏幕上「繪製」,但這不是我想要做的。
我以爲UIBeizerPath moveToPoint會幫助,但它只是弄亂了事情。
我在做什麼錯?
- (id)initWithFrame:(CGRect)frame
{
//default line properties
myPath=[[UIBezierPath alloc]init];
myPath.lineCapStyle=kCGLineCapRound;
myPath.miterLimit=0;
myPath.lineWidth=lineWidth;
brushPattern=[UIColor blackColor];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint curPoint = [[touches anyObject] locationInView:self];
lastPoint = curPoint;
[myPath moveToPoint:lastPoint];
[pathArray addObject:myPath];
[self setNeedsDisplay];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint curPoint = [[touches anyObject] locationInView:self];
myPath.lineWidth=lineWidth;
brushPattern=[UIColor redColor]; //red to show it hasn't been added yet.
[myPath moveToPoint:tempPoint];
[self setNeedsDisplay];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint curPoint = [[touches anyObject] locationInView:self];
myPath.lineWidth=lineWidth;
brushPattern=[UIColor blackColor]; //finalize the line with black color
[myPath addLineToPoint:curPoint];
[self setNeedsDisplay];
}
謝謝你的交易。將它們保存到數組中並重繪。未來有什麼機會會回來並咬我的? – JasonBourne
我無法想象任何問題。那裏沒有太多!但是你會發現一些基本問題,所以如果你需要在未來的某個時間進行其他的實施,那麼你的武裝很好。 – Rob
我感謝你的幫助!它讓我生氣了! – JasonBourne