我试图实现一种方法,绘制一个基于手势识别的行,但我无法获得UIBezierPath显示。我知道手势识别器正在运行,因为每次激活该方法时都会打印记录。同样让我困惑的是,我之前绘制的蓝线试图绘制贝塞尔路径,但贝塞尔路径却没有。即使我手动添加任意点没有被绘制,比如:UIBezierPath没有绘制
[myPath addLineToPoint:CGPointMake(50, 50)];
这里是我的UIView代码:
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(ctx, 0, 0, 1.0, 1);
CGContextMoveToPoint(ctx, 0, 150);
CGContextAddLineToPoint(ctx, 480, 150);
CGContextStrokePath(ctx);
[myPath addLineToPoint:CGPointMake(50, 50)];
[myPath stroke];
}
- (IBAction)handlePan:(UIPanGestureRecognizer *) recognizers {
CGPoint translation = [recognizers translationInView:self];
NSLog(@"Logged");
[myPath addLineToPoint:CGPointMake(translation.x, translation.y)];
[self setNeedsDisplay];
}
感谢您的帮助!
你为什么要画与CG和一些与NSBezierPath一些路径之前调用移动到mypath中呢? myPath定义在哪里?请包括它的定义,以便我们看看它在做什么。 – user1118321
谢谢你的回应!对不起,遗漏了初始值设定项。在 - (id)initWithFrame:(CGRect)框架中,我初始化为: 'myPath = [[UIBezierPath alloc] init]; [myPath moveToPoint:CGPointMake(0,0)];' – JShaev