【发布时间】:2012-06-13 21:42:46
【问题描述】:
我正在尝试实现一种基于手势识别绘制线条的方法,但我无法显示 UIBezierPath。我知道手势识别器正在运行,因为每次激活该方法时我都会打印以记录。让我感到困惑的是,我在尝试绘制 BezierPath 之前绘制的蓝线会显示,但 BezierPath 不会。即使我手动添加任意点也不会绘制任何内容,例如:
[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在哪里定义?请包括它的定义,以便我们可以看到它在做什么。 -
感谢您的回复!很抱歉省略了初始化程序。在 - (id)initWithFrame:(CGRect)frame 我这样初始化:
myPath=[[UIBezierPath alloc]init]; [myPath moveToPoint:CGPointMake(0, 0)];
标签: ios uiview uigesturerecognizer drawrect uibezierpath