我想制作自定义键盘。我完成了所有功能,但无法在我的应用中实现滑动功能。当我在键盘上滑动时,字母输入正确但线条(绘图)无法完美绘制。我无法删除旧的路径。请帮助。我想要这种类型的滑动。
我写这段代码
- (void)touchesBegan: (NSSet *)touches withEvent: (UIEvent *)event {
CGPoint location = [[touches anyObject] locationInView:self];
myPath=nil;
[_myPathArray removeAllObjects];
myPath=[[UIBezierPath alloc]init];
myPath.lineCapStyle=kCGLineCapRound;
myPath.lineWidth=5.0;
_brushPattern=[UIColor redColor];
_myArray=[[NSMutableArray alloc]init];
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath moveToPoint:[mytouch locationInView:self]];}
-(void)touchesMoved:(NSSet *)touches withEvent: (UIEvent *)event {
CGPoint location = [[touches anyObject] locationInView:self];
[myPath addLineToPoint:location];
shapeLayer.path = myPath.CGPath;
shapeLayer.strokeColor = _brushPattern.CGColor;
shapeLayer.lineWidth = 3.0;
shapeLayer.fillColor = [[UIColor clearColor] CGColor];
[self.layer addSublayer:shapeLayer];
[self setNeedsDisplay];}